I am building a WCF service. I need to store reference data in the cache which I will look up every time I receive input from the method... What is the right way to do this?
Rather than expiring the cache data every so often, you can actually just make sure to invalidate the cache whenever the underlying data you are caching changes.
See this example from info Q http://www.infoq.com/news/2011/04/Attribute-Caching
[Cache.Cacheable("UserTransactionCache")]
public DataTable GetAllTransactionsForUser(int userId)
{
return new DataProvider().GetAllTransactionsForUser(userId);
}
[Cache.TriggerInvalidation("UserTransactionCache")]
public void DeleteAllTransactionsForUser(int userId)
{
...
}