c# - Nopcommerce PerRequestCacheManager 与 MemoryCacheManager

标签 c# asp.net-mvc-3 caching nopcommerce

我正在开发 NopCommerce 2.40 。我想使用CacheManager在主页上设置缓存。

    var cacheModel = _cacheManager.Get(cacheKey, () =>
                {
                    var model = new HomePageProductsModel()
                     {
                    ....
                    ....

                     }
                  return model;
                });

当我调试这段代码时。它命中了MemoryCacheManager中的Get方法。现在,在管理端,当我更新任何产品时,我想通过 key 删除此缓存。下面调用的Remove方法会点击PerRequestCacheManager的Remove。

 _cacheManager.Remove(string.Format("product.hometemplate-{0}-{1}", storeid, true));

所以主页上的这个缓存没有被删除。有什么办法解决吗

最佳答案

Nop.Web项目中的一些 Controller 使用MemoryCacheManager。这些具有静态缓存 (MemoryCacheManager) 的 Controller 在\Nop.Web\Infrastruct\DependencyRegistrar.cs 文件中定义。在此文件中,我们定义应注入(inject)哪一个 ICacheManager 实现。

但我建议您使用 nopCommerce 中使用的相同方法。使用事件。订阅\Nop.Web\Infrastruct\Cache\ModelCacheEventConsumer.cs 文件中的产品插入/删除/更新事件并在那里重置缓存。只需看看它是如何完成的。

关于c# - Nopcommerce PerRequestCacheManager 与 MemoryCacheManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24776686/

相关文章:

asp.net - 在 mvc3 中的 Get Call 上将数据从 View 传递到 Controller

java - 在 Guava Cache 对象上启用统计信息的性能损失是多少?

c# - 在运行时将 PictureBox 添加到窗体

c# - 如何POST到rest api并使用c#中的非结束流?

c# - 在导航属性上定义数据注释

asp.net-mvc-3 - 替换 Asp.net MVC Razor 中的 TextAreaFor 代码

c++ - C++开源缓存推荐

java - java中只使用key对象的引用的缓存(而不是hashCode或equals)

c# - WPF中如何使用数据注解进行单位换算

c# - 反射(reflection):如何创建一个精确过滤的程序集类型列表?