public bool CreateEntry <TValue>(IPartitionObjectKey key, TValue?value, CancellationTokenSource tokenSourceBeforeComputingValue, double slidingCacheInMinutes, long?size = null, Action <ICacheEntry>?configureEntry = null) { // Prevent keys from other partitions if (!key.PartitionKey.Equals(PartitionKey)) { return(false); } var entry = Cache.CreateEntry(key); entry.SetValue(value); // TODO size will not be optional if (size.HasValue) { entry.Size = size; Interlocked.Add(ref _totalSize, (int)size.Value); } Interlocked.Increment(ref _partitionCount); SetExpiration(entry, tokenSourceBeforeComputingValue, slidingCacheInMinutes, configureEntry); RegisterEvictionCallback(size, entry); // need to manually call dispose instead of having a using"); // in case the factory passed in throws, in which case we"); // do not want to add the entry to the cache"); entry.Dispose(); return(true); }
public bool Remove(IPartitionObjectKey key) { // Prevent keys from other partitions if (!key.PartitionKey.Equals(PartitionKey)) { return(false); } Cache.Remove(key); return(true); }
public bool TryGetValue <TValue>(IPartitionObjectKey key, out TValue?value) { // Prevent keys from other partitions if (!key.PartitionKey.Equals(PartitionKey)) { value = default; return(false); } Interlocked.Increment(ref _accessCount); if (Cache.TryGetValue(key, out value)) { return(true); } Interlocked.Increment(ref _misses); return(false); }
public static bool CreateEntry <T>(this CachePartition cache, IPartitionObjectKey key, T value, Action <ICacheEntry> configureEntry = null) { return(cache.CreateEntry(key, value, cache.ClearCacheTokenSource, 10, null, configureEntry)); }