Skip to content

feat: add support for custom CacheTagInvalidator#121

Closed
euaaaio wants to merge 1 commit intodulnan:mainfrom
euaaaio:claude/custom-cache-tag-invalidator-011CV49HjWftBNeAvExMQFHW
Closed

feat: add support for custom CacheTagInvalidator#121
euaaaio wants to merge 1 commit intodulnan:mainfrom
euaaaio:claude/custom-cache-tag-invalidator-011CV49HjWftBNeAvExMQFHW

Conversation

@euaaaio
Copy link
Contributor

@euaaaio euaaaio commented Nov 12, 2025

This change allows users to provide a custom cache tag invalidator implementation, enabling them to:

  • Implement custom invalidation logic (debounce, queue, immediate, etc.)
  • Store tags buffer in custom storage (MongoDB, Redis, etc.)
  • Add logging, metrics, or monitoring
  • Integrate with external invalidation systems

Changes:

  • Created CacheTagInvalidator interface with single add(tags) method
  • Renamed CacheTagInvalidator class to InMemoryCacheTagInvalidator
  • Added cacheTagInvalidator option to MultiCacheServerOptions
  • Updated multiCache plugin to use factory pattern for invalidator initialization
  • Added comprehensive documentation with MongoDB example
  • Updated all tests to use InMemoryCacheTagInvalidator
  • Exported CacheTagInvalidator type from module

The API follows factory pattern (similar to cacheTagRegistry):

export default defineMultiCacheOptions(() => {
  return {
    cacheTagInvalidator: (cache, cacheTagRegistry) => {
      return new MyCustomInvalidator(cache, cacheTagRegistry, mongoConnection)
    }
  }
})

This change allows users to provide a custom cache tag invalidator implementation, enabling them to:
- Implement custom invalidation logic (debounce, queue, immediate, etc.)
- Store tags buffer in custom storage (MongoDB, Redis, etc.)
- Add logging, metrics, or monitoring
- Integrate with external invalidation systems

Changes:
- Created CacheTagInvalidator interface with single `add(tags)` method
- Renamed CacheTagInvalidator class to InMemoryCacheTagInvalidator
- Added cacheTagInvalidator option to MultiCacheServerOptions
- Updated multiCache plugin to use factory pattern for invalidator initialization
- Added comprehensive documentation with MongoDB example
- Updated all tests to use InMemoryCacheTagInvalidator
- Exported CacheTagInvalidator type from module

The API follows factory pattern (similar to cacheTagRegistry):
```typescript
export default defineMultiCacheOptions(() => {
  return {
    cacheTagInvalidator: (cache, cacheTagRegistry) => {
      return new MyCustomInvalidator(cache, cacheTagRegistry, mongoConnection)
    }
  }
})
```
@euaaaio
Copy link
Contributor Author

euaaaio commented Nov 12, 2025

Oh, sorry. That was my own experiment.

@euaaaio euaaaio closed this Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants