Exemple #1
0
        /// <summary>
        /// Adds an object to the cache. It is upto the implementer on how long it wishes to keep the item in cache.
        /// Typically it will be govered by the TimeToExpire property being set.
        /// </summary>
        /// <param name="key">Key which will be used to retrieve the same object.</param>
        /// <param name="value">The instance of the object that should be stored in cache.</param>
        public void Add(string key, object value)
        {
            Asserter.AssertIsNotNullOrEmptyString("key", key);
            Asserter.AssertIsNotNull("value", value);

            LocalCacheStorage.Add(key, value);
        }
Exemple #2
0
        /// <summary>
        /// Adds an object to the cache and uses generic type.
        /// </summary>
        /// <param name="timeout">Time the object should be kept, after which it can be disposed.</param>
        /// <param name="key">Key which will be used to retrieve the same object.</param>
        /// <param name="value">The instance of the object that should be stored in cache.</param>
        public void Add <T>(TimeSpan timeout, string key, T value)
        {
            Asserter.AssertIsNotNullOrEmptyString("key", key);
            Asserter.AssertIsNotNull("value", value);

            LocalCacheStorage.Add(key, value);
        }
Exemple #3
0
        /// <summary>
        /// Retrives an object from cache using the specified key.
        /// </summary>
        /// <param name="key">Key which will be used to retrieve the same object.</param>
        /// <returns>Object retrieved from the cache based on the key specified.</returns>
        public object Get(string key)
        {
            Asserter.AssertIsNotNullOrEmptyString("key", key);
            object value = null;
            object returnValue;

            if (LocalCacheStorage.TryGetValue(key, out returnValue))
            {
                value = returnValue;
            }

            return(value);
        }
Exemple #4
0
        /// <summary>
        /// Updates an object in cache.
        /// </summary>
        /// <param name="key">The key of the item to update.</param>
        /// <param name="value">The value to update it to.</param>
        public void Update(TimeSpan timeout, string key, object value)
        {
            Asserter.AssertIsNotNullOrEmptyString("key", key);
            Asserter.AssertIsNotNull("value", value);
            object returnValue;

            if (LocalCacheStorage.TryGetValue(key, out returnValue))
            {
                LocalCacheStorage[key] = value;
            }
            else
            {
                throw new CacheKeyNotFoundException(key, CacheStoreName, GetType());
            }
        }
Exemple #5
0
 /// <summary>
 /// Clears the entire LocalCacheStore of all items.
 /// </summary>
 public void FlushAll()
 {
     LocalCacheStorage.Clear();
 }
Exemple #6
0
 /// <summary>
 /// Checks whether the cache contains the specified key or not.
 /// </summary>
 /// <param name="key">Key which will be used to check whether the cache contains it or not.</param>
 /// <returns>true if the cache contains the specified key; otherwise, false.</returns>
 public bool ContainsKey(string key)
 {
     Asserter.AssertIsNotNullOrEmptyString("key", key);
     return(LocalCacheStorage.ContainsKey(key));
 }
Exemple #7
0
 /// <summary>
 /// Removes an object from the cache using the specified key.
 /// </summary>
 /// <param name="key">Key which will be used to remove the same object from cache.</param>
 public void Remove(string key)
 {
     Asserter.AssertIsNotNullOrEmptyString("key", key);
     LocalCacheStorage.Remove(key);
 }