[GH-ISSUE #1314] Make secondary-storage also compatible with ttl cache by providing db fallback option #8690

Closed
opened 2026-04-13 03:51:03 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @Scooter1337 on GitHub (Jan 30, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1314

Is this suited for github?

  • Yes, this is suited for github

I use memcached with a ttl of 60 minutes, but after this the cache will return 'undefined/null' and the user is instantly logged out.

There is also no way to get this to work at the moment, if you also want to use memcached rate-limiting.

Describe the solution you'd like

How can I make it fallback to get cache -> if no value -> get database.

Describe alternatives you've considered

Removing both secondary storage and rate-limiting

Additional context

Just a simple 'fallbackToDatabase' option in session would be plenty.

Originally created by @Scooter1337 on GitHub (Jan 30, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1314 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I use memcached with a ttl of 60 minutes, but after this the cache will return 'undefined/null' and the user is instantly logged out. There is also no way to get this to work at the moment, if you also want to use memcached rate-limiting. ### Describe the solution you'd like How can I make it fallback to get cache -> if no value -> get database. ### Describe alternatives you've considered Removing both secondary storage and rate-limiting ### Additional context Just a simple 'fallbackToDatabase' option in session would be plenty.
GiteaMirror added the locked label 2026-04-13 03:51:03 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 11, 2025):

Hi, @Scooter1337. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • Feature request to enhance secondary storage compatibility with TTL cache.
  • Current setup with memcached and 60-minute TTL causes user logouts when cache is empty.
  • Proposed solution: 'fallbackToDatabase' option to retrieve data from the database if cache is empty.
  • No activity or comments on the issue since it was opened.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If there is no response, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:2963383299 --> @dosubot[bot] commented on GitHub (Jun 11, 2025): Hi, @Scooter1337. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - Feature request to enhance secondary storage compatibility with TTL cache. - Current setup with memcached and 60-minute TTL causes user logouts when cache is empty. - Proposed solution: 'fallbackToDatabase' option to retrieve data from the database if cache is empty. - No activity or comments on the issue since it was opened. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If there is no response, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@Bekacru commented on GitHub (Jun 16, 2025):

you can enable session.storeSessionInDatabase

<!-- gh-comment-id:2975282743 --> @Bekacru commented on GitHub (Jun 16, 2025): you can enable `session.storeSessionInDatabase`
Author
Owner

@StashOfCode commented on GitHub (Aug 5, 2025):

@Bekacru, it writes to both db and cache which defeats the purpose of cache - speed. Would be perfect if there was an option to read/write to the db only when the cache server is down.

Current options are either 'fast but risky' or 'slow but safe', with no 'fast with fallback' option.

<!-- gh-comment-id:3154597070 --> @StashOfCode commented on GitHub (Aug 5, 2025): @Bekacru, it writes to both db and cache which defeats the purpose of cache - speed. Would be perfect if there was an option to read/write to the db only when the cache server is down. Current options are either 'fast but risky' or 'slow but safe', with no 'fast with fallback' option.
Author
Owner

@dosubot[bot] commented on GitHub (Nov 4, 2025):

Hi, @Scooter1337. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested a fallbackToDatabase option to ensure secondary storage compatibility with TTL cache, preventing issues like instant user logout when the cache is empty.
  • Current setups, especially with memcached and rate-limiting, lack this fallback functionality.
  • A suggestion was made to enable session.storeSessionInDatabase, but you and others noted this defeats the cache speed advantage.
  • The need remains for a true fallback that reads from the database only if the cache is down.
  • No resolution has been reached, and the issue has seen limited recent activity.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here.
  • If I don’t hear back within 7 days, I will automatically close this issue.

Thanks for your understanding and contribution!

<!-- gh-comment-id:3486877223 --> @dosubot[bot] commented on GitHub (Nov 4, 2025): Hi, @Scooter1337. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested a `fallbackToDatabase` option to ensure secondary storage compatibility with TTL cache, preventing issues like instant user logout when the cache is empty. - Current setups, especially with memcached and rate-limiting, lack this fallback functionality. - A suggestion was made to enable `session.storeSessionInDatabase`, but you and others noted this defeats the cache speed advantage. - The need remains for a true fallback that reads from the database only if the cache is down. - No resolution has been reached, and the issue has seen limited recent activity. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here. - If I don’t hear back within 7 days, I will automatically close this issue. Thanks for your understanding and contribution!
Author
Owner

@Scooter1337 commented on GitHub (Nov 4, 2025):

Hi, @Scooter1337. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested a fallbackToDatabase option to ensure secondary storage compatibility with TTL cache, preventing issues like instant user logout when the cache is empty.
  • Current setups, especially with memcached and rate-limiting, lack this fallback functionality.
  • A suggestion was made to enable session.storeSessionInDatabase, but you and others noted this defeats the cache speed advantage.
  • The need remains for a true fallback that reads from the database only if the cache is down.
  • No resolution has been reached, and the issue has seen limited recent activity.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here.
  • If I don’t hear back within 7 days, I will automatically close this issue.

Thanks for your understanding and contribution!

Still relevant

<!-- gh-comment-id:3487024514 --> @Scooter1337 commented on GitHub (Nov 4, 2025): > Hi, @Scooter1337. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. > > **Issue Summary:** > - You requested a `fallbackToDatabase` option to ensure secondary storage compatibility with TTL cache, preventing issues like instant user logout when the cache is empty. > - Current setups, especially with memcached and rate-limiting, lack this fallback functionality. > - A suggestion was made to enable `session.storeSessionInDatabase`, but you and others noted this defeats the cache speed advantage. > - The need remains for a true fallback that reads from the database only if the cache is down. > - No resolution has been reached, and the issue has seen limited recent activity. > > **Next Steps:** > - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here. > - If I don’t hear back within 7 days, I will automatically close this issue. > > Thanks for your understanding and contribution! Still relevant
Author
Owner

@dosubot[bot] commented on GitHub (Feb 3, 2026):

Hi, @Scooter1337. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested a fallbackToDatabase option for TTL cache setups to retrieve session data from the database if the cache returns undefined or null, preventing user logouts.
  • The issue was marked stale previously, but you confirmed it is still relevant.
  • A suggestion to enable session.storeSessionInDatabase was made, but you and others noted this negates the cache speed benefits.
  • The core need remains a true fallback mechanism that only reads from the database when the cache is unavailable.
  • No resolution or implementation has been made yet.

Next Steps:

  • Please confirm if this feature request is still relevant to the latest version of better-auth by commenting on this issue.
  • If no response is received within 7 days, I will automatically close the issue.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3842247430 --> @dosubot[bot] commented on GitHub (Feb 3, 2026): Hi, @Scooter1337. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested a `fallbackToDatabase` option for TTL cache setups to retrieve session data from the database if the cache returns undefined or null, preventing user logouts. - The issue was marked stale previously, but you confirmed it is still relevant. - A suggestion to enable `session.storeSessionInDatabase` was made, but you and others noted this negates the cache speed benefits. - The core need remains a true fallback mechanism that only reads from the database when the cache is unavailable. - No resolution or implementation has been made yet. **Next Steps:** - Please confirm if this feature request is still relevant to the latest version of better-auth by commenting on this issue. - If no response is received within 7 days, I will automatically close the issue. Thank you for your understanding and contribution!
Author
Owner

@github-actions[bot] commented on GitHub (Apr 1, 2026):

This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.

<!-- gh-comment-id:4166560083 --> @github-actions[bot] commented on GitHub (Apr 1, 2026): This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8690