vc-platform icon indicating copy to clipboard operation
vc-platform copied to clipboard

Platform cache is ineffective

Open asvishnyakov opened this issue 5 years ago • 2 comments

Problem: Currently we store objects in cache using the following cache keys: ServiceNameMethodName-Param1-Param2-Param3. So if we lad objects by id and put array of objects [A, B, C] to cache, but then asking for [B, C, D], all objects of second request will loaded from db, despite the fact B & C already in cache, but in another group.

Solution: Objects should be stored in cache individually, only Response Group may make difference.

Proposal of changes:

  1. When we get objects by id, just store them individually
  2. When we search objects by search criteria, then: 2.1. Get objects ids by search criteria. If exist in cache then from cache, otherwise from database and store result in cache using search criteria as key and ids as value 2.2 Load objects by ids. If exist in cache then from cache, otherwise from database and store results in cache individually

Advantages

  1. We will have less number of requests to database
  2. Cache will use less memory

Disadvantages No one, except increasing complexity of code

asvishnyakov avatar Sep 02 '19 09:09 asvishnyakov

What are you suggested is absolutely unachievable! Due to many factors such as sorting, paging and different search conditions that can be applied only on the data source.

tatarincev avatar Dec 26 '19 15:12 tatarincev

@tatarincev You may disagree with my proposal, but the problem is still here

asvishnyakov avatar Dec 26 '19 16:12 asvishnyakov

Fixed in the following PRs: https://github.com/VirtoCommerce/vc-platform/pull/2486 https://github.com/VirtoCommerce/vc-platform/pull/2593

artem-dudarev avatar Apr 14 '23 08:04 artem-dudarev