Skip to content

fix(cache): enable expiration for permissions namespace in system cache#26295

Merged
rijkvanzanten merged 2 commits intodirectus:mainfrom
clintmoyer:issue-25513
Dec 24, 2025
Merged

fix(cache): enable expiration for permissions namespace in system cache#26295
rijkvanzanten merged 2 commits intodirectus:mainfrom
clintmoyer:issue-25513

Conversation

@clintmoyer
Copy link
Contributor

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:

  1. Set CACHE_SYSTEM_TTL=60m
  2. Start Directus server
  3. Check TTL of any permission key in the system cache

What's changed:

  • adds CacheConfigRedis.ttl
  • updates KvRedis.set() to use TTL
  • uses environment variable CACHE_SYSTEM_TTL
  • new unit test Custom TTL

Potential Risks / Drawbacks

  • None

Tested Scenarios

  • CACHE_SYSTEM_TTL=60m
  • CACHE_SYSTEM_TTL unset

For CACHE_SYSTEM_TTL=60m we expect 0 < TTL < 3600s

$ redis-cli KEYS "permissions:*" | head -n1
permissions:raw-permissions-4d52183c

$ redis-cli TTL permissions:raw-permissions-4d52183c   
3510

For unset CACHE_SYSTEM_TTL we expect TTL = -1 (no expiration)

$ redis-cli KEYS "permissions:*" | head -n1
permissions:raw-permissions-72007481

$ redis-cli TTL permissions:raw-permissions-72007481
-1

Review Notes / Questions

  • None

Checklist

  • Added or updated tests
  • Documentation PR created here or not required
  • OpenAPI package PR created here or not required

Fixes #25513

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 rijkvanzanten self-assigned this Dec 24, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 KvRedis class by accepting an optional ttl configuration parameter
  • Updates the set() method to use Redis PX (milliseconds) flag when TTL is configured
  • Configures the permissions cache to use CACHE_SYSTEM_TTL via the getMilliseconds utility

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

@rijkvanzanten rijkvanzanten merged commit f6f632e into directus:main Dec 24, 2025
17 checks passed
@rijkvanzanten
Copy link
Member

Thanks @clintmoyer! 🫶

@github-actions github-actions bot added this to the Next Release milestone Dec 24, 2025
@codecov
Copy link

codecov bot commented Dec 24, 2025

Codecov Report

❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.86%. Comparing base (9f6c797) to head (b4590af).
⚠️ Report is 3 commits behind head on main.

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     
Flag Coverage Δ
api 44.52% <80.00%> (-0.11%) ⬇️
app 74.83% <ø> (-0.06%) ⬇️
composables 82.35% <ø> (ø)
create-directus-extension 94.44% <ø> (ø)
create-directus-project 98.43% <ø> (ø)
env 99.67% <ø> (ø)
errors 97.47% <ø> (ø)
extensions 35.63% <ø> (ø)
extensions-registry 95.27% <ø> (ø)
extensions-sdk 14.38% <ø> (ø)
format-title 100.00% <ø> (ø)
memory 95.64% <91.66%> (-0.12%) ⬇️
pressure 77.63% <ø> (ø)
release-notes-generator 81.14% <ø> (ø)
schema-builder 80.59% <ø> (ø)
sdk 25.95% <ø> (+0.01%) ⬆️
storage 92.00% <ø> (ø)
storage-driver-azure 76.76% <ø> (ø)
storage-driver-cloudinary 81.14% <ø> (ø)
storage-driver-gcs 69.72% <ø> (ø)
storage-driver-local 69.76% <ø> (ø)
storage-driver-s3 46.73% <ø> (ø)
storage-driver-supabase 68.63% <ø> (ø)
system-data 71.42% <ø> (-0.39%) ⬇️
update-check 55.67% <ø> (ø)
utils 90.26% <ø> (ø)
validation 44.50% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Api: Permissions cache keeps growing

3 participants