public Task <(bool, T)> TryGet([NotNull] THash key) { return(_cache.TryGetValue(IWeakCacheProvider <T, THash> .HashKey(key), out var weakRef) && weakRef.Target is { } target ? Task.FromResult((true, target)) : Task.FromResult((false, (T)null))); }
public void Detach(THash associateWith) { using var sem = new SemaphoreSlim(1); var path = Path.Combine(initDirectory, IWeakCacheProvider <T, THash> .HashKey(associateWith) + "."); if (File.Exists(path)) { fileMapping.TryRemove(associateWith, out _); File.Delete(path); } }
public void Attach(ref T key, THash associateWith) { if (associateWith == null || key == null) { return; } var weakRef = new WeakEntry <T>(key); key = null; _cache.TryAdd(IWeakCacheProvider <T, THash> .HashKey(associateWith), weakRef); }
public void Attach(ref T key, THash associateWith) { if (associateWith == null || key == null) { return; } var path = Path.Combine(initDirectory, IWeakCacheProvider <T, THash> .HashKey(associateWith) + ".tmp"); if (!File.Exists(path)) { var s = cachingPolicy(key); key = null; Task.Run(() => { fileMapping.TryAdd(associateWith, path); WriteFile(path, s); }); } }
public void Detach(THash associateWith) { _cache.TryRemove(IWeakCacheProvider <T, THash> .HashKey(associateWith), out _); }