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.