VirtoCommerce / vc-storefront-deprecated

VirtoCommerce Storefront for ASP.NET (.NET Framework) repository (DEPRECATED)
http://virtocommerce.com
Other
26 stars 113 forks source link

IDistributedCacheManager Information Request #77

Closed collinstevens closed 4 years ago

collinstevens commented 5 years ago

I'm looking to enable the IDistributedCacheManager, but it seems that the IDistributedCacheManager isn't used anywhere. The ILocalCacheManager is used in several places, such as CartBuilder.cs, where I believe it could be using IDistributedCacheManager instead to work in a load balanced scenario.

I'm sure the IDistributedCacheManager must be used somewhere, but I can not find any usings of the interface or the class, DistributedCacheManager, in the code.

1) What is the purpose of IDistributedCacheManager? 2) Why hasn't it replaced ILocalCacheManager in most places?

yecli commented 5 years ago

Hi @collinstevens.

Really, IDistributedCacheManager is not used except in registration. Probably its registration was left for custom modules, if they used it. Distributed cache logic is implemented using MichaCo CacheManager, which uses Redis for multiple instances synchronization: https://github.com/VirtoCommerce/vc-storefront/blob/8803c642c8ebda9f6ebcaee7d838c5ea22305459/VirtoCommerce.Storefront/Startup.cs#L124-L172.

Please note https://github.com/VirtoCommerce/vc-storefront is deprecated, you could use NET Core https://github.com/VirtoCommerce/vc-storefront-core storefront instead.

tatarincev commented 5 years ago

In addition to written, IDistributedCacheManager is not used even in the new storefront version https://github.com/VirtoCommerce/vc-storefront-core. Thus this fact make a each storefront instance stateful especially for shopping cart functionality, therefore you must always worry about user sessions when use scale out with multiple application instances with load balancer. (ARR session cookies as one of solutions).

Also @yecli mentioned about memory cached data consistency between multiple instances, when Redis server is play role of cache events broadcaster between multiple platform instances, where each instance used this events to keep cached data in local memory in consistency. image Read more about how to configure scale out for the platform you might by this link https://virtocommerce.com/docs/vc2devguide/deployment/platform-scaleout

But it is works only for the platform apps, for storefront this logic is not implemented yet even in new storefront version. So better solution IMHO in order to make the application truly stateless, is need to used distributed cache for all logic that store client session on the server. (shopping cart, favorites and etc)

collinstevens commented 5 years ago

Thank you for the quick and detailed replies.

I would much prefer to have stateless instances so I can perform blue/green deployments without worrying about losing cache during this. Sticky instances using ARR is a code smell to me.

We are planning to migrate our customized vc-platform to the core version near the end of this year, but we have integrations to other internal services and a lot of divergence from upstream which makes this difficult.

Is the plan for the future of vc-storefront to have a cache heirarchy with a local cache for each instance and a distributed cache? Similar to a CPU cache heirarchy with L1/L2? If so, is there a ticket tracking this feature?

tatarincev commented 5 years ago

Now we are going to start big changes with storefront architecture as part of implementation "Headless" concept and lot of business logic will be migrated into platform side in the special "headless" modules and are many issues with stateless will be resolved along the way. I'll send you more information about "Headless" project when it will be ready for publication.

tatarincev commented 4 years ago

Please look at this storefront release https://github.com/VirtoCommerce/vc-storefront-core/releases/tag/v4.1.0 there is introduced Hybrid cache mode that should completely solve cached data consistency between multiple storefront instances.

collinstevens commented 4 years ago

@tatarincev this new hybrid cache mode seems to go against the plan to have Storefront become stateless. Did the plan change?