For objects with strict timeliness such as products, the background data has been updated, and the places where these data are used should also need to be updated. The observer pattern is usually used to solve this kind of problem, the core of which lies in publish and subscribe. There are many specific implementation solutions. You can use Guava's Eventbus within the application, or you can use nosql such as redis. Personally, it is recommended to use redis to complete it. At the same time, redis can also be used as a second-level cache.
No matter how you update the product data in the cache, it is very time-consuming and will increase the complexity of the system, and the data may not be updated and read in real time; so it is recommended to store it in the shopping cartskuId和购买的amount , read the product data from the product cache when swiping the shopping cart; and update the product cache after the product is updated, which can reduce the system complexity caused by updating product information and save a lot of memory
For objects with strict timeliness such as products, the background data has been updated, and the places where these data are used should also need to be updated. The observer pattern is usually used to solve this kind of problem, the core of which lies in publish and subscribe. There are many specific implementation solutions. You can use Guava's Eventbus within the application, or you can use nosql such as redis. Personally, it is recommended to use redis to complete it. At the same time, redis can also be used as a second-level cache.
No matter how you update the product data in the cache, it is very time-consuming and will increase the complexity of the system, and the data may not be updated and read in real time; so it is recommended to store it in the shopping cart
skuId
和购买的amount
, read the product data from the product cache when swiping the shopping cart; and update the product cache after the product is updated, which can reduce the system complexity caused by updating product information and save a lot of memory