質問

I would like to ask you if there is a way to extend the cache manager in order to use Redis or Memcached.

I've noticed that all cache managers in Nop.Core implement the ICacheManager interface. Is there a way to write my own cache manager (using Memcached for example) implementing the ICacheManager Interface and if so , how is possible to initialize nop commerce engine using my own memcached manager?

役に立ちましたか?

解決 2

It's not possible to serialize NopCommerce domain model objects. Not supported yet. You will get stackoverflow exception because of circular referencing properties.

While serializing is not possible, you can't replace implemented ICacheManager with a disributed one like Redis or Memecached.

Somehow if you manage to serialize domain objects, deserializing will block your way also. After deserializing you need to attach the objects to ObjectContext to keep Entity Framework based queries work.

NopCommerce team has started to do some implemetations for Azure. Hopefully they will also support distibuted cache soon.

他のヒント

I will post my research results for others to use.

So, to use your own cache manager you have to write your own cachemanager class implementing the ICachaManager interface.

The other nopcommerce cache managers are located at Nop.Core.Caching so it will be wise to also put your own manager in there.

Then you should add the following line below line 121 where the other nopcommerce cache managers are registed at DependencyRegistrar.cs file in Nop.Web.Framework project.

builder.RegisterType<MyOwnAwesomeCacheManager>().As<ICacheManager>().Named<ICacheManager>("my_own_awesome_cachemanager").InstancePerHttpRequest();

Then at Nop.Web.Infrastructure.Cache at the ModelCacheEventConsumer.cs file replace the code at the class constructor to "tell" nop commerce to use your own cache manager.

 this._cacheManager = EngineContext.Current.ContainerManager.Resolve<ICacheManager>("my_own_awesome_cachemanager");

Hope I'm not missing anything.

This is for nopcommerce 3.20.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top