fix(cache): enable expiration for permissions namespace in system cache#26295
Merged
rijkvanzanten merged 2 commits intodirectus:mainfrom Dec 24, 2025
Merged
fix(cache): enable expiration for permissions namespace in system cache#26295rijkvanzanten merged 2 commits intodirectus:mainfrom
rijkvanzanten merged 2 commits intodirectus:mainfrom
Conversation
Enables the expiration of keys for the "permissions" namespace in the Redis system cache. Updates the @directus/memory package to pass TTL when adding new keys. It adds the Time-to-Live (TTL) field to the CacheConfigRedis interface. Updates the KvRedis.set() method to use this TTL value for setting the expiration for keys. The TTL is sourced from the CACHE_SYSTEM_TTL environment variable, defaulting to -1 (no expiration) if not specified. Refs: #25513
rijkvanzanten
approved these changes
Dec 24, 2025
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the permissions cache to respect the CACHE_SYSTEM_TTL environment variable for Redis-based caching. Previously, permission keys in the Redis system cache were not expiring even when CACHE_SYSTEM_TTL was configured.
Key Changes:
- Adds TTL support to the
KvRedisclass by accepting an optionalttlconfiguration parameter - Updates the
set()method to use RedisPX(milliseconds) flag when TTL is configured - Configures the permissions cache to use
CACHE_SYSTEM_TTLvia thegetMillisecondsutility
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/memory/src/kv/lib/redis.ts | Adds ttl property to KvRedis class and updates set() method to apply TTL to Redis SET commands when configured |
| packages/memory/src/cache/types/config.ts | Adds optional ttl field to CacheConfigRedis interface with JSDoc documentation |
| api/src/permissions/cache.ts | Imports and uses CACHE_SYSTEM_TTL environment variable to configure TTL for permissions cache |
| packages/memory/src/kv/lib/redis.test.ts | Adds test case to verify TTL is correctly passed to Redis SET command |
| .changeset/rare-swans-know.md | Documents the fix in the changeset for both @directus/memory and @directus/api packages |
| contributors.yml | Adds contributor clintmoyer to the contributors list |
Member
|
Thanks @clintmoyer! 🫶 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #26295 +/- ##
==========================================
- Coverage 62.90% 62.86% -0.04%
==========================================
Files 2105 2098 -7
Lines 136189 135776 -413
Branches 8236 8232 -4
==========================================
- Hits 85673 85361 -312
+ Misses 50516 50415 -101
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
Enables the expiration of keys for the "permissions" namespace in the Redis system cache. Currently it does not respect the value of
CACHE_SYSTEM_TTL.Reproduce:
CACHE_SYSTEM_TTL=60mWhat's changed:
CacheConfigRedis.ttlKvRedis.set()to use TTLCACHE_SYSTEM_TTLCustom TTLPotential Risks / Drawbacks
Tested Scenarios
CACHE_SYSTEM_TTL=60mCACHE_SYSTEM_TTLunsetFor
CACHE_SYSTEM_TTL=60mwe expect0 < TTL < 3600sFor unset
CACHE_SYSTEM_TTLwe expectTTL = -1(no expiration)Review Notes / Questions
Checklist
Fixes #25513