Service1 -> Our Wrapper API service -> Redis
Service2 -> Our Wrapper API service -> Redis
Client side caching with Redis is very useful. Redis provides server push-based cache invalidation for client side cache in 2 modes:
- Default mode: Redis keeps a mapping of all clients(services) and the key they requested on the server side and sends requests for invalidation when data changes for keys.
- Broadcast mode: Sends invalidation to all clients whenever any key changes and expects clients to update their local cache.
Problem
We have a use case in which we are building a platform service over Redis for some use cases and exposing APIs for clients to consume. We want the clients should not directly talk to Redis and talk via our API.
- The problem here is how would Redis server push based cache invalidation work?
- How would cache invalidation requests reach the clients(services) when we have an API layer in between. We do not wish the clients to directly talk to Redis and talk only via an API, do not want to leak the database to the clients, want to keep it internal.
Question
Do I need to implement my own push based cache invalidation layer then? Maintain clients who connect to my API and garbage collect the dead ones etc...? Is there anything better I could do and use the Redis cache invalidation or extend it for this use case?