0

I am creating an application where I am using caching to reduce the latency and load on my DB. The problem I am facing is the caching client I am using provides async call for publishing data to remote distributed cache so I am not able to figure out how to handle such behavior.

For eg. - there is variable X=10 present in both DB and cache.So when X changes its value to X=20 I want to ensure at both DB and cache its value gets updated. For DB I am able to make a sync call so its fine there but with cache I have async method which returns void so I can't enough to ensure the successful cache publish scenario.

The thing is I don't want to read stale data from cache I always want to read updated latest data.

Is there any workaround for such kind of problems ?

Gal Dreiman
  • 3,969
  • 2
  • 21
  • 40
Bruce_Wayne
  • 1,564
  • 3
  • 18
  • 41
  • What about using a caching solution with cluster support ? – HRgiger Apr 09 '17 at 13:27
  • The value of X can change using your program? or manually using a DB query? – Gal Dreiman Apr 09 '17 at 13:53
  • @GalDreiman my program will change X and then update it first to DB and then to cache. so that next time during reterival it gets updated value from cache given TTL for X is not expired. Any suggestions ? – Bruce_Wayne Apr 09 '17 at 19:43
  • @HRgiger It doesn't matter whether my caching server is single host or a cluster if the call to publish X is async I am not able to figure out whether it got succeeded or not. isn't it ? – Bruce_Wayne Apr 09 '17 at 19:45
  • Async interfaces typically have a notification mechanism. Please tell us about your async client and show some code snippet how you do it now. – cruftex Apr 10 '17 at 02:38
  • @cruftex no it doesn't have any notification mechanism. Can't share the code, I have explained everything in my question and comments, please go through them again. Also considering there is no notification mechanism can you help me with this ? Is there any hack I can put ? One such solution I thought of is hitting a get call to cache having some delay after publish to cache call, but I am not finding this as a suitable approach as it will increase latency for my application. – Bruce_Wayne Apr 11 '17 at 04:52
  • What you want is consistency of cache and database. The consistency problem is way beyond the actual problem you want so solve, updating the cache simultaneous does not protect for stale data reads. Stackoverflow is for one specific question, however, your consistency requirements and available interfaces need to be carefully assessed to find a suitable solution. You will find some Q&As regarding database consistency on Stackoverflow. If you like contact me via email, you can find it on my GitHub profile. – cruftex Apr 12 '17 at 01:49

0 Answers0