Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Domain object changes - refresh on cached lists needed

Problem

We have a complex domain model. To avoid performance issues, most of the list (generated from domain objects) are cached. Everything works well until the first domain object changes. All depending list in the cache must be refreshed - the question is: how?

Example

  • Domain object: House
  • Action: Name of a house has been changed
  • Effect: all list (containts house names) are out-of-date, refresh needed

Solutions

No doubt, there is a very easy way: after saving a domain object, we refresh all list from code manually.

Pseudo code

repository.Save(save);

cacheManager.Invalidate("HouseList");
cacheManager.Invalidate("OrderedHouseList");
cacheManager.Invalidate("HousecombinedWithResidentsList");
...

So the problem is: we have to refresh everything manually. I'm looking for better solutions, let's say:

  • Aspect oriented way w/ PostSharp or Windsor
  • Observer or event based technique
  • CQRS it's about separating queries and commands, but this conception is maybe too much.

Any idea or experience?

like image 272
boj Avatar asked Nov 14 '22 05:11

boj


1 Answers

The answer to this question is complex because your requirements are unclear. Can data be stale? If so, how long?

Based on the limited information in your post, I would suggest the "cached" views merely being a query over the real data. The queries themselves could periodically refresh their cached results given some interval.

like image 116
Judah Gabriel Himango Avatar answered Dec 28 '22 08:12

Judah Gabriel Himango