wabbajack/Wabbajack.VFS/FallthroughVFSCache.cs
Timothy Baldridge 3c28cdf7b9 Add Cesi cache
2022-06-21 19:38:42 -06:00

37 lines
847 B
C#

using System.Threading;
using System.Threading.Tasks;
using Wabbajack.DTOs.Vfs;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.VFS.Interfaces;
namespace Wabbajack.VFS;
public class FallthroughVFSCache : IVfsCache
{
private readonly IVfsCache[] _caches;
public FallthroughVFSCache(IVfsCache[] caches)
{
_caches = caches;
}
public async Task<IndexedVirtualFile?> Get(Hash hash, CancellationToken token)
{
foreach (var cache in _caches)
{
var result = await cache.Get(hash, token);
if (result == null) continue;
return result;
}
return default;
}
public async Task Put(IndexedVirtualFile file, CancellationToken token)
{
foreach (var cache in _caches)
{
await cache.Put(file, token);
}
}
}