/** * Provides implementation of Add method of the ICacheStorage interface. Add the key value pair to * the store. * * * @param key key * @param item object * @return returns the result of operation. */ @Override public StoreAddResult Add(Object key, Object item, boolean allowExtentedSize) { try { if (ServerMonitor.getMonitorActivity()) { ServerMonitor.LogClientActivity("Store.Add", ""); } if (_itemDict.containsKey(key)) { return StoreAddResult.KeyExists; } StoreStatus status = HasSpace((ISizable) item, allowExtentedSize); if (_reportCacheNearEviction) { CheckForStoreNearEviction(); } if (status == StoreStatus.HasNotEnoughSpace) { return StoreAddResult.NotEnoughSpace; } _itemDict.put(key, item); super.Added((ISizable) ((item instanceof ISizable) ? item : null)); if (status == StoreStatus.NearEviction) { return StoreAddResult.SuccessNearEviction; } } catch (OutOfMemoryError e) { return StoreAddResult.NotEnoughSpace; } catch (RuntimeException e) { throw e; } return StoreAddResult.Success; }
/** * Provides implementation of Remove method of the ICacheStorage interface. Removes an object from * the store, specified by the passed in key * * @param key key * @return object */ @Override public Object Remove(Object key) { if (ServerMonitor.getMonitorActivity()) { ServerMonitor.LogClientActivity("Store.Remove", ""); } Object e = Get(key); if (e != null) { _itemDict.remove(key); super.Removed((ISizable) ((e instanceof ISizable) ? e : null)); } return e; }
/** * Provides implementation of Insert method of the ICacheStorage interface. Insert/Add the key * value pair to the store. * * * @param key key * @param item object * @return returns the result of operation. */ @Override public StoreInsResult Insert(Object key, Object item, boolean allowExtentedSize) { try { if (ServerMonitor.getMonitorActivity()) { ServerMonitor.LogClientActivity("Store.Insert", ""); } Object oldItem = _itemDict.get(key); StoreStatus status = HasSpace( (ISizable) ((oldItem instanceof ISizable) ? oldItem : null), (ISizable) item, allowExtentedSize); if (_reportCacheNearEviction) { CheckForStoreNearEviction(); } if (status == StoreStatus.HasNotEnoughSpace) { return StoreInsResult.NotEnoughSpace; } _itemDict.put(key, item); super.Inserted( (ISizable) ((oldItem instanceof ISizable) ? oldItem : null), (ISizable) ((item instanceof ISizable) ? item : null)); if (status == StoreStatus.NearEviction) { // the store is almost full, need to evict. return oldItem != null ? StoreInsResult.SuccessOverwriteNearEviction : StoreInsResult.SuccessNearEviction; } return oldItem != null ? StoreInsResult.SuccessOverwrite : StoreInsResult.Success; } catch (OutOfMemoryError e) { return StoreInsResult.NotEnoughSpace; } catch (RuntimeException e) { throw e; } }
/** Removes all entries from the store. */ @Override public void Clear() { _itemDict.clear(); super.Cleared(); }
/** * Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged * resources. */ @Override public void dispose() { _itemDict.clear(); _itemDict = null; super.dispose(); }