private static void RemoveCacheEntry(object key, object value, EvictionReason reason, object state) { if (value is MediaBuffer buffer) { buffer.Release(); } }
private async void PostEvictionCallback(object key, object value, EvictionReason reason, object state) { try { var credentials = (await this.metaService.GetSettingsAsync()).GetAzureDevOpsCredentialsOrThrowException(); var match = FeedRegex.Match(key.ToString()); // Regenerate a set of updated data var feed = this.mapper.Map <Models.Feed>( await this.client.GetFeedAsync( new ApiUser(credentials.Username, credentials.Token), match.Groups["Name"].Value, "Prerelease")); this.cache.Set($"feeds:<{match.Groups["Name"].Value}>", feed, DataCacheTimeout); // Re-set the cache to be reloaded in 35min this.UpdateReset(match.Groups["Name"].Value); } catch (Exception exception) { this.logger.LogError(exception, "Error while fetching the packages feed."); } }
/// <summary> /// Called when an item is removed from the index. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <param name="reason">The reason.</param> /// <param name="state">The state.</param> protected void EvictionCallback(object key, object?value, EvictionReason reason, object state) { if (EvictionReason.Expired == reason || reason == EvictionReason.Capacity || reason == EvictionReason.TokenExpired) { TagIndex.Remove(key); } }
private static void InvokeCallbacks(CacheEntry entry) { var callbackRegistrationList = Interlocked.Exchange(ref entry._postEvictionCallbacks, null); if (callbackRegistrationList == null) { return; } foreach (var callbackRegistration in callbackRegistrationList) { try { PostEvictionDelegate evictionCallback = callbackRegistration.EvictionCallback; if (evictionCallback != null) { object key = entry.Key; object obj = entry.Value; EvictionReason evictionReason = entry.EvictionReason; object state = callbackRegistration.State; evictionCallback.Invoke(key, obj, evictionReason, state); } } catch (Exception ex) { } } }
private void OnCacheRecordExpire(object key, object value, EvictionReason reason, object state) { recordsKeyList.Remove((string)key); }
private static void PostEvictionDelegateWrapper(object key, object value, EvictionReason reason, object state, Action <string, object, CacheRemovalReason> removalCallback) { string s; bool removed = StandardCacheHelper.CacheKeys.TryRemove(key.ToString(), out s); // track independently of memory cache removalCallback?.Invoke(key.ToString(), value, ConvertRemovedReason(reason)); }
private void EvictionCallback(object key, object value, EvictionReason reason, object state) { if (reason == EvictionReason.Expired || reason == EvictionReason.Capacity || reason == EvictionReason.Removed) { this._keys.Remove(key.ToString()); } }
private void CacheItemRemoved(object key, object value, EvictionReason reason, object state) { if (value != null && value is CacheItem) { ((CacheItem)value).Dispose(); } }
private void ChangeTokenEvicted(object key, object value, EvictionReason reason, object state) { if (value is DependencyChangeToken dependencyChangeToken) { dependencyChangeToken.NotifyChanged(); } }
// Handle cache item expiring private void OnRemovedFromCache(object key, object value, EvictionReason reason, object state) { if (reason != EvictionReason.Expired) { return; } // Now actually handle file event var e = (FileSystemEventArgs)value; var msg = $"Uploading file {e.FullPath} {e.ChangeType}"; _logger.LogDebug(msg); try { var response = _uploadService.Upload(_settings.Username, e.FullPath).Result; _logger.LogDebug(response); _logger.LogDebug("Upload completed"); } catch (UploadException ex) { _logger.LogError(ex.Message); } }
private void EvictionNotice(object key, object value, EvictionReason reason, object state) { if (reason != EvictionReason.Replaced && reason != EvictionReason.Removed) { logger?.LogDebug($"Cache Key {key} evicted for reason: {reason} "); } }
public void SetOverwritesWithReplacedReason() { var cache = CreateCache(); var value1 = new object(); string key = "myKey"; var callback1Invoked = new ManualResetEvent(false); EvictionReason actualReason = EvictionReason.None; var options1 = new MemoryCacheEntryOptions(); options1.PostEvictionCallbacks.Add(new PostEvictionCallbackRegistration() { EvictionCallback = (subkey, subValue, reason, state) => { actualReason = reason; var localCallbackInvoked = (ManualResetEvent)state; localCallbackInvoked.Set(); }, State = callback1Invoked }); var result = cache.Set(key, value1, options1); Assert.Same(value1, result); var value2 = new object(); result = cache.Set(key, value2); Assert.True(callback1Invoked.WaitOne(TimeSpan.FromSeconds(3)), "Callback1"); Assert.Equal(EvictionReason.Replaced, actualReason); }
private void EvictionCallback(object key, object value, EvictionReason reason, object state) { var message = $"Entry was evicted. Reason: {reason}."; _cache.Set("", message); }
private void ItemRemoved(object key, object value, EvictionReason reason, object state) { var strKey = key as string; if (string.IsNullOrWhiteSpace(strKey)) { return; } if (reason == EvictionReason.Removed) { return; } if (strKey.Contains(":")) { if (strKey.Contains("@")) { var region = Regex.Match(strKey, "@(.+?):").Groups[1].Value; this.Stats.OnRemove(region); } else { this.Stats.OnRemove(); } } }
private void OnPostEvictionCallback(object key, object value, EvictionReason reason, object state) { if (reason == EvictionReason.Removed) { this.OnChanged(new CacheChangedEventArgs(this.ConvertReason(reason), key.ToString(), value)); } }
private static void EvictionCallback(object key, object value, EvictionReason reason, object state) { if (value is IDisposable disposable) { disposable.Dispose(); } }
private void onDropCacheEntry(object key, object value, EvictionReason reason, object state) { var logger = (ILogger <ImageCacheMiddleware>)state; logger.LogInformation($"Image [{value}] will be removed [{reason}] from cache"); File.Delete((string)value); }
private void PostEvictionCallback(object key, object value, EvictionReason reason, object state) { if (reason != EvictionReason.Replaced) { this._cacheEntries.TryRemove(key, out var _); } }
virtual protected void PostEvictionCallback(object key, object value, EvictionReason reason, object state) { var cachable = value as ICachable; Interlocked.Add(ref _memoryUsed, -cachable.SizeInBytes); Interlocked.Decrement(ref _itemsCount); }
private void PostEvictionCallback(object key, object value, EvictionReason reason, object state) { if (reason != EvictionReason.TokenExpired) { return; } if (value is IDictionary <string, Queue <Func <bool> > > dictionary) { var projectChanged = false; foreach (var keyValue in dictionary) { var actions = keyValue.Value; while (actions.Count > 0) { var action = actions.Dequeue(); if (!projectChanged) { projectChanged = action?.Invoke() == true; } else { action?.Invoke(); } } } GroupingCompleted?.Invoke(projectChanged); } }
private void CachedCallBack(object key, object value, EvictionReason reason, object state) { var s3readCount = GetFileFromS3(@"News/S3ReadCount.json").Result; if (s3readCount == null) { // return new NewsCategories(); } var s3count = DeserializeObject <NewsCategories>(s3readCount); // var today = DateTime.Today.ToString("dd-MM-yyyy"); // var todaycount = new CategoryModel { CategoryId = 0, Name = $"{today}-CallBack" }; // if (s3count.Categories.Any(s => s.Name == $"{today}-CallBack")) // todaycount = s3count.Categories.First(s => s.Name == $"{today}-CallBack"); // if (todaycount != null) // { // s3count.Categories.Remove(todaycount); // } // todaycount.CategoryId = todaycount.CategoryId + 1; // s3count.Categories.Add(todaycount); // var jsonString = JsonSerializer.Serialize(s3count); //var update = SaveFileAsync(@"News/S3ReadCount.json", jsonString).Result; }
private static void DependentEvictionCallback(object key, object value, EvictionReason reason, object state) { var message = $"Parent entry was evicted. Reason: {reason}."; ((HomeController)state)._cache.Set(CacheKeys.DependentMessage, message); }
protected override void EvictionCallback(object key, object value, EvictionReason reason, object state) { Logger.Verbose("{key} message evicted", (key as ByteString).ToCorrelationId()); var message = (CorrelatableMessage <ProtocolMessage>)value; _evictionEvent.OnNext(new MessageEvictionEvent <ProtocolMessage>(message, message.Content.PeerId)); }
private void SetWeakReference(object key, object value, EvictionReason reason, object state) { if (reason == EvictionReason.Expired) { _memoryCache.Set(key, new WeakReference(value)); } }
private static void MyCallBack(object key, object value, EvictionReason reason, object state) { var message = $"Cache entry was removed : {reason}"; ((DemoController)state) ?.memoryCache ?.Set <string>("callBackMessage", message); }
private void OnCacheRecordExpire(object key, object value, EvictionReason reason, object state) { lock (syncObject) recordsKeys.Remove((string)key, out _); }
public static void PostEvictionCallback(object key, object value, EvictionReason reason, object state) { var message = $"Cache entry {key} => {value} was removed : {reason}"; //_theLock.TryRemove(key: (TKey)key, value: out TValue o); Debug.WriteLine(message); }
private void CallbackForDeleteClient(object key, object value, EvictionReason reason, object state) { if (reason == EvictionReason.Expired) { _logger.LogDebug($"CallbackForDeleteClient call expire"); _badDisconnectSocketService.DisconnectClient(key.ToString()); } }
private static void CacheActionAllRemovedCallback(object key, object value, EvictionReason reason, object state) { // Do something clever on cache Key removed. if (reason == EvictionReason.Capacity) { // Log memory issues for cache. } }
private void MyCallback(object key, object value, EvictionReason reason, object state) { var message = $"Cache entry state change:{key} {value} {reason} {state}"; _memoryCache.Set("callbackMessage", message); Console.WriteLine(message); }
internal void SetExpired(EvictionReason reason) { IsExpired = true; if (EvictionReason == EvictionReason.None) { EvictionReason = reason; } DetachTokens(); }
protected virtual void PostEvictionCallback(object key, object value, EvictionReason reason, object state) { var collection = value as StatCollection; if (collection != null) { collection.IsEvicted = true; } var record = value as StatRecord; if (record != null) { record.Collection = null; } //Console.Write("E"); }
protected override void PostEvictionCallback(object key, object value, EvictionReason reason, object state) { var collection = value as StatCollection; if (collection != null) { Task.Run(() => { collection.IsEvicted = true; var task = StoreCollection(collection, true); task.ConfigureAwait(false); task.Wait(); Console.Write("E"); collection.Records.Clear(); }).ConfigureAwait(false); } var record = value as StatRecord; if (record != null) { record.Collection = null; } }
private void AfterEvicted(string key, object value, EvictionReason reason, object state) { Console.WriteLine("Evicted. Value: " + value + ", Reason: " + reason); }