2014-07-16 4 views
1

저는 NopCommerce 2.40에서 작업하고 있습니다. CacheManager를 사용하여 홈 페이지에서 Cache를 설정하려고합니다.Nopcommerce PerRequestCacheManager 대 MemoryCacheManager

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

        } 
        return model; 
       }); 

이 코드를 디버깅 할 때. 그것은 MemoryCacheManager에서 Get 메소드를 친다. 이제 관리자 쪽에서 어떤 제품을 업데이트 할 때 Key로이 캐시를 제거하려고합니다. 아래에있는 PerRequestCacheManager의 Remove 메소드를 제거하십시오.

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

홈페이지의 캐시는 삭제되지 않습니다. 어떤 해결책이 있습니까?

답변

3

Nop.Web 프로젝트의 일부 컨트롤러는 MemoryCacheManager를 사용합니다. 정적 캐시 (MemoryCacheManager)가있는 제어기는 \ Nop.Web \ Infrastructure \ DependencyRegistrar.cs 파일에 정의됩니다. 이 파일에서 우리는 ICacheManager 구현 중 어느 것을 주입해야하는지 정의합니다.

하지만 nopCommerce에서 사용되는 것과 동일한 방법을 사용하는 것이 좋습니다. 이벤트 사용. \ Nop.Web \ Infrastructure \ Cache \ ModelCacheEventConsumer.cs 파일의 제품 삽입/삭제/업데이트 이벤트를 구독하고 캐시를 다시 설정하십시오. 이미 이미 완료된 방법을 확인하십시오.

+0

감사합니다. @ and.maz. 이 문은 builder.RegisterType ()를 사용하여 ImportManager 서비스에 대한 DependencyRegistrar를 변경했습니다. () .WithParameter (ResolvedParameter.ForNamed ("nop_cache_static")) InstancePerHttpRequest(); ImportManager에서 캐시를 지우는 방법을 쓰고 있기 때문에 괜찮을까요? –

+0

현재 MemoryCache는 60 분으로 설정되어 있습니다. 수동으로 제거하기 전까지는 영원히 가질 수 있습니다. 매일 그것을 제거하려고합니다. –