Click here to Skip to main content
15,896,118 members
Articles / Web Development / ASP.NET

Advance Caching with Shared Cache

Rate me:
Please Sign up or sign in to vote.
4.33/5 (7 votes)
12 Feb 2009GPL36 min read 61.3K   691   52  
This article describes how to implement advance level caching with SharedCache.
using System;
using System.Collections.Generic;
using MergeSystem.Indexus.WinServiceCommon.Provider.Cache;

namespace AdvanceCacheDemo
{
    /// <summary>
    /// A wrapper class to provide cache manipulation
    /// </summary>
    class CacheUtil
    {
        /// <summary>
        /// Add an object to cache with specified key
        /// </summary>
        /// <param name="key">A key value to asscociate with given object</param>
        /// <param name="obj">An object to store into cache</param>
        public static void Add(string key, object obj)
        {
            IndexusDistributionCache.SharedCache.Add(key, obj);
        }
        /// <summary>
        /// Retrieve an object from cache using given key value
        /// </summary>
        /// <param name="key">A key value to retrieve object from hash</param>
        /// <returns>An object that is associated with given key value</returns>
        public static object Get(string key)
        {
            return IndexusDistributionCache.SharedCache.Get(key);
        }

        /// <summary>
        /// Remove an object from cache using given key value
        /// </summary>
        /// <param name="key">A key value to remove item from cache</param>
        /// <returns>Result of remove operation true or false</returns>
        public static bool Remove(string key)
        {
            return IndexusDistributionCache.SharedCache.Remove(key);
        }
        /// <summary>
        /// List all objects present in cache
        /// </summary>
        /// <param name="serverName">Name of server for retrieving cache items</param>
        /// <returns>List of objects from cache</returns>
        public static List<Object> GetObjectList(string serverName)
        {
            List<Object> objs = new List<object>();
            foreach  (string k in IndexusDistributionCache.SharedCache.GetAllKeys(serverName))
            {
                objs.Add(IndexusDistributionCache.SharedCache.Get(k));
            }
            return objs;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Architect
Canada Canada
Ashutosh is an avid programmer, who “lives to code”. One can always find him busy seeking challenging programming assignments on various complex problems ranging from Data management, Classification, Optimization, Security, Network analysis, Distributed computing.

He started his programming stint with “C”; he has also worked on C++, Visual Basic, JAVA, Perl, FoxPro, PASCAL, Shell Scripting, and Perl. Currently, he is proficient and working on C#.

His area of interest includes Distributed Computing, Analytic and Business Intelligence, Large Enterprise System Architectures, Enterprise Content Management.

He is an advocate of Open source and likes to share solutions with open source communities like
1.Stack Overflow
2. nHibernate
.

Award's :
Prize winner in Competition "Best article of May 2008"

Articles :
Click to see my CodeProject Articles

Blog :
Share a solution | Explore the .NET world

Link'd :


His Favorite(s) :
nHibernate - The best ORM.
nHibernate Contributed Tools

Comments and Discussions