We currently use Akka Distributed Data for synchronizing a authorization-cache (thing-cache, policy-cache) between all services which either read (search, gateway) or update (things, policies) this data.
This works fine, but creates unnecessary network load because the whole cache is distributed to all shards, even if a shard does not need the data. Another disadvantage of the current approach is that the "Akka Distributed Data" cache cannot be cleared, which may cause memory problems in the long run.
In this task, we should at least address the following issues:
remove policy-cache from search: sync via events and full-sync fallback (without cache) has been tested and works fine
replace "Akka Distributed Data" with a local cache per shard, holding only the data relevant for this shard
implement the cache as an LRU cache with a configurable maximum size
the cache-entries should be lazy-loaded on first access
update the cache whenever the cached data changes (e.g. by Events via PubSub), the things-service and policy-service should no longer write to the cache actively
to make sure that the cache is eventually consistent even when events get lost, let the cache entries expire after a configurable time: a re-load will be necessary on next access
to further optimize memory usage, remove entries from the cache which have not been accessed for a configurable time
We currently use Akka Distributed Data for synchronizing a authorization-cache (thing-cache, policy-cache) between all services which either read (search, gateway) or update (things, policies) this data. This works fine, but creates unnecessary network load because the whole cache is distributed to all shards, even if a shard does not need the data. Another disadvantage of the current approach is that the "Akka Distributed Data" cache cannot be cleared, which may cause memory problems in the long run.
In this task, we should at least address the following issues:
Caffeine seems to be a good choice for a local cache implementation: https://github.com/ben-manes/caffeine