Skip to content

feat(session): add CacheSessionStorage driver#395

Merged
usernane merged 3 commits into
devfrom
feat/cache-session-storage
Jun 14, 2026
Merged

feat(session): add CacheSessionStorage driver#395
usernane merged 3 commits into
devfrom
feat/cache-session-storage

Conversation

@usernane

Copy link
Copy Markdown
Member

Summary

Add a cache-backed session storage driver that delegates to the cache library's Storage interface.

Motivation

Sessions were limited to file or database storage. Production deployments need Redis-backed sessions for horizontal scaling. The cache library already ships with RedisStorage — this adapter bridges it to the session layer.

Changes

  • New class: WebFiori\Framework\Session\CacheSessionStorage
  • Implements SessionStorage by delegating to any WebFiori\Cache\Storage backend
  • Configurable key prefix and TTL
  • Added to phpunit coverage source list

How to Test / Verify

11 unit tests with 100% line coverage. Run:

vendor/bin/phpunit --filter CacheSessionStorageTest

Usage

// Redis-backed sessions:
$redis = new \Redis();
$redis->connect("127.0.0.1", 6379);
$storage = new CacheSessionStorage(new RedisStorage($redis));
SessionsManager::setStorage($storage);

// File-cache-backed sessions:
$storage = new CacheSessionStorage(new FileStorage("/tmp/sessions"));
SessionsManager::setStorage($storage);

Breaking Changes and Migration Steps

None.

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • I added/updated tests (or explained why not)
  • I updated docs (if needed) Docs Repo
  • I ran lint/cs-fixer (if applicable)
  • I considered backward compatibility
  • I considered security

Related issues

Closes #337

@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.72%. Comparing base (b982bd6) to head (c9a0bde).
⚠️ Report is 4 commits behind head on dev.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev     #395      +/-   ##
============================================
+ Coverage     83.67%   83.72%   +0.04%     
- Complexity     3067     3077      +10     
============================================
  Files           103      104       +1     
  Lines          9018     9045      +27     
============================================
+ Hits           7546     7573      +27     
  Misses         1472     1472              
Flag Coverage Δ
php-8.1 82.59% <ø> (ø)
php-8.2 82.59% <ø> (ø)
php-8.3 92.11% <100.00%> (+0.02%) ⬆️
php-8.4 92.11% <100.00%> (+0.02%) ⬆️
php-8.5 91.98% <100.00%> (+0.03%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

Adapter that implements SessionStorage using the cache library's
Storage interface. Supports any cache backend (Redis, file, etc.).

- Configurable key prefix for namespace isolation
- Configurable TTL (default: 7200s)
- Cache-level encryption disabled (sessions have their own)
- 100% test coverage (11 tests, 18/18 lines)

Closes #337
@usernane usernane force-pushed the feat/cache-session-storage branch from 46f626d to 2496203 Compare June 14, 2026 07:55
@usernane usernane merged commit 9485367 into dev Jun 14, 2026
5 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant