private void removedCallback(string key, Object value, CacheItemRemovedReason reason) { BubblingRoll obj = (BubblingRoll)value; obj.Save(); // if the application is shutdown before save, the change is lost. (ie. local test server) if (reason == CacheItemRemovedReason.Expired) { insertNew(key, obj.Id, obj.ListSize); } }
private BubblingRoll insertNew(string key, string id, int list_size) { BubblingRoll obj = new BubblingRoll(id, list_size); // if concurrency happens, this will be done more than once. // todo: don't insert into cache for nonexistent board id (bad user request). HttpRuntime.Cache.Insert(key, obj, null, DateTime.Now.AddSeconds(HeartsConfiguration.DEFAULT_CACHE_SECONDS), Cache.NoSlidingExpiration, CacheItemPriority.Default, removedCallback); // expires after some time for multi-node synchronization (unreliable). return(obj); }
private BubblingRoll get(string id, int list_size) { string key = SandId.CombineId(BubblingRoll.PAR_KEY_PREFIX, id); BubblingRoll obj = (BubblingRoll)HttpRuntime.Cache.Get(key); if (obj == null) { obj = insertNew(key, id, list_size); } return(obj); }