Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a big problem.

I have to created cache in .net console application, then how can I access console application cache in my asp.net project. My cache updated in every one hour in console application. I want to access console application cache in my asp.net web application.

Please help me.

Thank you........
Posted

1 solution

Hi NagaRaju

In my opinion it would be good practice to move your logic off your console application and into a separate class library that can be accessed by both the console and web apps.

I use something along the lines of the code below in my repositories to cache static data. The repositories are in their own class library and can be used by a web app, console app, windows app, etc. In the example below I'm using the classes from the System.Runtime.Caching library...

C#
public class CacheManager
{
    public static object GetCachedItem(string key)
    {
        return MemoryCache.Default[key];
    }

    public static void AddItem(string key, object item)
    {
        var expiration = int.Parse(ConfigurationManager.AppSettings[key]);

        var policy = new CacheItemPolicy
                         {
                             Priority = CacheItemPriority.NotRemovable,
                             AbsoluteExpiration = DateTimeOffset.Now.AddHours(expiration)
                         };

        MemoryCache.Default.Set(key, item, policy);
    }
}


Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900