vc-platform
vc-platform copied to clipboard
Platform cache is ineffective
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:
- When we get objects by id, just store them individually
- 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
- We will have less number of requests to database
- Cache will use less memory
Disadvantages No one, except increasing complexity of code
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 You may disagree with my proposal, but the problem is still here
Fixed in the following PRs: https://github.com/VirtoCommerce/vc-platform/pull/2486 https://github.com/VirtoCommerce/vc-platform/pull/2593