开发者

Update cached data

开发者 https://www.devze.com 2022-12-16 20:48 出处:网络
U are caching a list of items, then Add or update or delete method called. Approach 1) A- Do the data change at the database. If success do B, C

U are caching a list of items, then Add or update or delete method called.

Approach 1)

A- Do the data change at the database. If success do B, C

B- Remove the entire list from the Cache.

C- Re-Cache the list on first read. 开发者_JAVA百科

Approach 2)

A- Do the data change at the database, If success do B

B- Do the same change at the cached items, and save more time.

Approach(2) probably will cause nasty difficult to spot bugs, because the data come from BLL and placed directly into cache, One can't assume no bugs will happen at the sproc, I am not worry about database runtime errors, runtime errors will show up, but I am worry about invalid data, or miss calculation.

Can I proceed with approach (2) with caution? Is there a "best practice" principle which suggest not doing approach(2)?


Well, personally I will not go for 2. Like you said it yourself, concurrency issues can cause nasty outcomes.

I will not drop (2) completely though if (1) is not 'good' enough.

Factors to consider:

  • Hit rates (read and edit/delete)
  • Number of records/items
  • Size of each item
  • etc etc...


You should also take into consideration, whether the data can be changed in the database from an other applicaton (which bypasses your cache). In these cases the second approach (2) might result in showing invalid data to the user.

I would suggest to measure the performance of both solutions, and use the second approach only when it has a well defined benefit comparing to the first one.

0

精彩评论

暂无评论...
验证码 换一张
取 消