Simple example of configuring Enterprise library Caching Block.

Download the Enterprise Library 5 from here

http://www.microsoft.com/en-in/download/details.aspx?id=15104

Create a new windows application.

We need the configuration information to setup the caching.

Open the EntLib Configuration console.

Open the app.config file of the windows application created.

Select Blocks à Add Caching Settings

It will add the required configuration information to the config file of the windows application.

Sample code implementing Caching block to save dictionary object in Cache.


public static class Configuration
{
public static Dictionary<string, string> GetConfigSettings()
{
// get the cache manager
ICacheManager cacheManager = CacheFactory.GetCacheManager();
var configSettings = (Dictionary<string, string>)cacheManager["configSettings"];

if (configSettings == null)
{
configSettings = new Dictionary<string, string>();
configSettings.Add("key1", "value1");
configSettings.Add("key2", "value2");

// add the dictionary object
cacheManager.Add("configSettings", configSettings);
}
else
{
// get from the configsettings object from the cache
configSettings = (Dictionary<string, string>) cacheManager["configSettings"];
}

return configSettings;
}
}

Bye.

 

 


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s