Synchronizing local and remote cache in distributed caching
Posted
by
ltfishie
on Programmers
See other posts from Programmers
or by ltfishie
Published on 2012-02-09T03:09:56Z
Indexed on
2012/10/30
23:19 UTC
Read the original article
Hit count: 301
With a distributed cache, a subset of the cache is kept locally while the rest is held remotely.
- In a get operation, if the entry is not available locally, the remote cache will be used and and the entry is added to local cache.
- In a put operation, both the local cache and remote cache are updated. Other nodes in the cluster also need to be notified to invalidate their local cache as well.
What's a simplest way to achieve this if you implemented it yourself, assuming that nodes are not aware of each other.
Edit My current implementation goes like this:
- Each cache entry contains a time stamp.
- Put operation will update local cache and remote cache
- Get operation will try local cache then remote cache
- A background thread on each node will check remote cache periodically for each entry in local cache. If the timestamp on remote is newer overwrite the local. If entry is not found in remote, delete it from local.
© Programmers or respective owner