2022-06-22 01:38:42 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2022-07-11 20:55:54 +00:00
|
|
|
using Wabbajack.DTOs.Streams;
|
2022-06-22 01:38:42 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-07-11 20:55:54 +00:00
|
|
|
public async Task<IndexedVirtualFile?> Get(Hash hash, IStreamFactory sf, CancellationToken token)
|
2022-06-22 01:38:42 +00:00
|
|
|
{
|
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)
|
2022-07-02 00:01:40 +00:00
|
|
|
{
|
2022-07-11 20:55:54 +00:00
|
|
|
result = await cache.Get(hash, sf, token);
|
2022-07-02 00:01:40 +00:00
|
|
|
if (result == null) continue;
|
|
|
|
foreach (var upperCache in _caches)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (upperCache != cache)
|
|
|
|
await upperCache.Put(result, token);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|