[PR #669] [MERGED] fix: ensure persistence to secondary storage upon storage eviction #3425

Closed
opened 2026-03-13 10:53:20 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/669
Author: @jstri
Created: 11/26/2024
Status: Merged
Merged: 11/28/2024
Merged by: @Bekacru

Base: mainHead: fix/self-heal-secondary-storage


📝 Commits (1)

  • a4662ec fix: ensure persistence to secondary storage upon cache eviction

📊 Changes

1 file changed (+43 additions, -19 deletions)

View changed files

📝 packages/better-auth/src/db/internal-adapter.ts (+43 -19)

📄 Description

In some cases (e.g., using Cloudflare Tiered Cache) secondary storage can be evicted during a session's lifetime, especially for long-lived sessions. After eviction, reads either return null or fallback to the database if the storeSessionInDatabase setting is enabled. This PR ensures that sessions are re-persisted to secondary storage under the following conditions:

  • secondaryStorage is configured
  • session is not found in secondary storage
  • session exists in database (storeSessionInDatabase setting is enabled)

This ensures that sessions can be retrieved from secondary storage on subsequent reads or if the session needs to be updated (due to extended expiration time), it can be saved in secondary storage as well.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/669 **Author:** [@jstri](https://github.com/jstri) **Created:** 11/26/2024 **Status:** ✅ Merged **Merged:** 11/28/2024 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `fix/self-heal-secondary-storage` --- ### 📝 Commits (1) - [`a4662ec`](https://github.com/better-auth/better-auth/commit/a4662eca345b3e05ed4957cc490fdffb2940773f) fix: ensure persistence to secondary storage upon cache eviction ### 📊 Changes **1 file changed** (+43 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/internal-adapter.ts` (+43 -19) </details> ### 📄 Description In some cases (e.g., using Cloudflare Tiered Cache) secondary storage can be evicted during a session's lifetime, especially for long-lived sessions. After eviction, reads either return `null` or fallback to the database if the `storeSessionInDatabase` setting is enabled. This PR ensures that sessions are re-persisted to secondary storage under the following conditions: - `secondaryStorage` is configured - session is not found in secondary storage - session exists in database (`storeSessionInDatabase` setting is enabled) This ensures that sessions can be retrieved from secondary storage on subsequent reads or if the session needs to be updated (due to extended expiration time), it can be saved in secondary storage as well. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 10:53:20 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#3425