为Web应用程序缓存设计模式
我们正在为ASP.NET MVC3应用程序使用memcache。为Web应用程序缓存设计模式
我想知道人们用来管理数据的推荐设计模式或库,因为会有这么多密钥会生成,因此管理它可能会有点痛苦,并找出哪些数据变得肮脏以及如何处理刷新数据,以便我们在缓存中拥有干净的数据副本,并且我们的数据完整性在那里,并且不会进入脏缓存。
感谢 Saarthak
这是有关缓存的文章在MVC 3大serieas:http://dotnetslackers.com/articles/aspnet/Cache-Exploration-in-ASP-NET-MVC-3-Part-1.aspx
感谢分享0lukasz0但这不是我所期待的。 – saarthak
我不知道如果我真的让你的问题,但是这是我用它来管理memcached的接入方式和钥匙 首先我还想说,这可能不是最好的办法,因为我是新来缓存
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;
}
}
这就是我如何生成我的钥匙
CLASSNAME + METHODNAME + PARAMS
这样,我结束了缓存的方法resultd
除此之外,如果高速缓存中的项比datetime差(interval)更早,则应实施缓存过期策略,您可以使用datetime作为缓存过期。转到数据库,否则将其放置在高速缓存中。从缓存中获取它。 – DarthVader
你说得对!如果你想单元测试你的缓存过期策略,你可以实现AmbientContext模式,而不是严格使用DateTime实现!它适用于我的硬件应用程序..! – renatoargh
Renota,您的答案符合我所寻找的解决方案。但这仍然是一个基本的实现。看看这篇文章 - http://www.alachisoft.com/resources/articles/domain-objects-caching-pattern.html 这家伙建议一个更好的方式来做事情。所以,我正在寻找一种可能被广泛使用的解决方案。 – saarthak
有多少数据是在缓存中?什么是缓存的平均大小?多少次读/写交易? – sll
我不完全知道,但肯定会碰到几个100MB。我们还没有实现缓存,但我们希望遵循行业推荐的做法。我们只是做了一个小实现来获得Memcache的一个挂件。找到一篇关于此的好文章 - http://www.alachisoft.com/resources/articles/domain-objects-caching-pattern.html 同样,想知道是否还有其他模式或实践正在遵循。谢谢 – saarthak