Reputation: 1014
we are using memcache for a ASP.NET MVC3 application.
I want to know recommended design patterns or libraries which people use to manage data, because there will be so many keys that will get generated that it might be little painful to manage then and figure out which data is getting dirty and how to refresh the data so that we have a clean copy of data in our cache and our data integrity is there and we don't get into dirty cache.
Thanks Saarthak
Upvotes: 1
Views: 1476
Reputation: 16519
I dont know if I really get your question, but this is the way I use to manage memcached access and keys First Id like to say that this might not be the best way as I am new to caching
public class City { String name; }
public interface CityRepository
{
City GetCityById(Int32 id);
}
public class SqlCityRepository : CityRepository
{
public City GetCityById(Int32 id)
{
//SQL CODE
return null;
}
}
public class MemcachedRepository : CityRepository
{
public CityRepository repository { get; set; }
public MemcachedRepository(CityRepository repository)
{
this.repository = repository;
}
public City GetCityById(Int32 id)
{
//IF(CHECK_IF_KEY_IS_PRESENT_AT_MEMCACHED)
// RETURN CACHED_VALUE(KEY);
//ELSE
var result = this.repository.GetCityById(id);
//ADD result TO CACHED ITEMS
return result;
}
}
And this is how I generate my keys
CLASSNAME + METHODNAME + PARAMS
This way I end up caching the method resultd
Upvotes: 1
Reputation: 3267
This is a great serieas of articles about caching at mvc 3: http://dotnetslackers.com/articles/aspnet/Cache-Exploration-in-ASP-NET-MVC-3-Part-1.aspx
Upvotes: 0