cacheable icon indicating copy to clipboard operation
cacheable copied to clipboard

Add store/layer identification to cache hooks for multi-store setups

Open tshtark opened this issue 8 months ago • 2 comments

Description

When using cache-manager with primary and secondary stores, there's currently no way to identify which specific store/layer served a cache hit when using the built-in multi-store functionality. This makes it impossible to implement proper monitoring and metrics collection per cache layer.

Current Behavior

When configuring cache-manager with primary and secondary stores, The emitted hooks are not specific to the cache layer they are associated with. This makes it difficult to track and monitor the performance of each layer.

Use Case

This feature is essential for:

  1. Performance Monitoring - Understanding cache layer utilization and hit rates
  2. Cost Optimization - Identifying if expensive layers (e.g., Redis) are being utilized effectively
  3. Debugging - Tracing which layer served specific requests
  4. Capacity Planning - Making informed decisions about cache layer sizing

tshtark avatar May 27 '25 10:05 tshtark

@tshtark - Thanks for submitting this. Right now we just use event emitter here to send out the store such as on get eventEmitter.emit('get', {key, error, store}); where right now we are doing eventEmitter.emit('get', {key, error});

jaredwray avatar May 30 '25 14:05 jaredwray

@tshtark - moving this to a vote and will keep live for 60 days. If we get enough people interested we will look at add this. If you want to do a pull request more than happy to help you on it. Just let me know

jaredwray avatar Jun 06 '25 19:06 jaredwray

Hey Guys 👋 I’ve opened a PR that implements this enhancement. It adds primary / secondary:N store identifiers to event payloads so users can track which layer served a cache hit.

faizanu94 avatar Aug 26 '25 06:08 faizanu94

These are rolling out today.

jaredwray avatar Aug 26 '25 21:08 jaredwray