wabbajack/Wabbajack.VFS/FallthroughVFSCache.cs

39 lines
917 B
C#
Raw Normal View History

2022-06-22 01:38:42 +00:00
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)
{
2022-06-29 13:18:04 +00:00
IndexedVirtualFile? result = null;
2022-06-22 01:38:42 +00:00
foreach (var cache in _caches)
{
2022-06-29 13:18:04 +00:00
if (result == null)
result = await cache.Get(hash, token);
else
await cache.Put(result, token);
2022-06-22 01:38:42 +00:00
}
2022-06-29 13:18:04 +00:00
return result;
2022-06-22 01:38:42 +00:00
}
public async Task Put(IndexedVirtualFile file, CancellationToken token)
{
foreach (var cache in _caches)
{
await cache.Put(file, token);
}
}
}