private void removedCallback(string key, Object value, CacheItemRemovedReason reason) { if (reason == CacheItemRemovedReason.Expired) { BlockPathsRoll obj = (BlockPathsRoll)value; // insertNew(key); // Not needed to keep it always in memory. } }
private BlockPathsRoll insertNew(string key) { BlockPathsRoll obj = new BlockPathsRoll(key); // if concurrency happens, this will be done more than once. // todo: should put empty blocks into cache for ? HttpRuntime.Cache.Insert(key, obj, null, DateTime.Now.AddSeconds(Config.DEFAULT_CACHE_SECONDS), Cache.NoSlidingExpiration, CacheItemPriority.Default, removedCallback); // expires after some time for multi-node synchronization (unreliable). return(obj); }
private BlockPathsRoll get(int block_idx_x, int block_idx_y) { // be careful of name conflict from other ponds using the same cache. string key = Config.DRAWING_PAR_KEY_PREFIX + block_idx_x.ToString() + ',' + block_idx_y.ToString(); BlockPathsRoll obj = (BlockPathsRoll)HttpRuntime.Cache.Get(key); if (obj == null) { obj = insertNew(key); } return(obj); }
public int AddPath(PathModel model) { int ret = DrawingStore.AddPath(model); if (ret == 0 || ret == 3) { string key = Config.DRAWING_PAR_KEY_PREFIX + model.BlockIndexX.ToString() + ',' + model.BlockIndexY.ToString(); BlockPathsRoll obj = (BlockPathsRoll)HttpRuntime.Cache.Get(key); if (obj != null) { obj.AddPath(model); } } return(ret); }
public IEnumerable <PathModel> GetBlockPaths(int block_idx_x, int block_idx_y) { BlockPathsRoll roll = this.get(block_idx_x, block_idx_y); return(roll.Get()); }