/// <summary> /// Inserts or updates an item to cache for the mentioned time span /// </summary> /// <typeparam name="T">Type of the object to insert or update</typeparam> /// <param name="key">Key of the item</param> /// <param name="value">Object to add/update to cache</param> /// <param name="timeSpan">Amount of time for which object needs to be persisted</param> /// <param name="overwrite">Flag to overwrite or not if already present with the key</param> /// <returns>True, if successfully added/updated</returns> public bool PutItem <T>(string key, object value, TimeSpan timeSpan, bool overwrite = true) { CacheItemPolicy policy = GetCachePolicy(timeSpan); return(this.PutItem(CacheUtils.GetCacheKey <T>(key), value, policy, overwrite)); }
/// <summary> /// Invalidate all objects /// </summary> /// <returns>True, if operation is succeeded</returns> public bool Invalidate() { bool returnVal = false; string key = CacheUtils.GetCacheKey(); lock (privateCacheLock) { Flush(key); returnVal = true; } return(returnVal); }
/// <summary> /// Invalidates an item from the cache with the supplied key /// </summary> /// <typeparam name="T">Type of object which is cached</typeparam> /// <param name="key">Key of the object</param> /// <returns>True, if operation is succeeded</returns> public bool Invalidate <T>(string key) { bool returnVal = false; key = CacheUtils.GetCacheKey <T>(key); lock (privateCacheLock) { if (privateCache.Contains(key)) { privateCache.Remove(key); returnVal = true; } } return(returnVal); }
/// <summary> /// Retrieves a generic item from the cache with the specified key /// </summary> /// <typeparam name="T">Type of cached object to retrieve</typeparam> /// <param name="key">Key of the item</param> /// <returns>Object retrieved</returns> public T GetItem <T>(string key) where T : class { return(privateCache.Get(CacheUtils.GetCacheKey <T>(key)) as T); }