One of the best way to improve Application performance is to Cache Data which is frequently Accessed or Retrieved from Database so that we can reduce the trip to Database and we can minimize or avoid the DB operations. MS Velocity offers in-memory caching. In this blog I am going to show how to cache the some of the frequently access the data .
In this Exercise I am going to use MS Free Database Chinook (Album ) as my data model. This Database has bunch of tables but I wanted to cache Customer and Album Tables. Here I am going to create WCF Service which expose to operations which returns list of All Albums and All Customers. Before creating WCF service I wanted to give brief introduction on the Caching API’s we are going to use. Here I am going to use the following two Caching Services APIs
To Add Reference to our WCF project we need select it from GAC ( Global Assembly Cache ). we can not add reference like other Assembly . GAC is nothing but a windows file Folder which is created when you install .NET Framework and its located @ C:\Windows\Assembly to add reference
Here is the Caching API’s Classes and Methods which we will be using in our code.
Here I am going to define the WCF Service which exposes two operations GetAllAlbums and GetAllCustomers
Here is the Caching Library implementation
using PowerShell Cmdlet we can verify our cache services first let is check our Cache Host using “Get-CacheHost”
Get-Cache will displays the Cache Names
Get-CacheStatistics will give you the details about Cached item and Request Count etc..
Next Blog post we will see how to set Caching services in Web.config
Nandri( Thanks)
SreenivasaRagavan.