PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 12, 2022

[FIXED] What happens to PHP sessions stored in Memcached if the Memcache instance hits its memory limit?

 November 12, 2022     memcached, php, session     No comments   

Issue

We're using a memcache cluster as a session store for multiple webservers.

I'm curious, though, what the effect will be if we set a long session expiry and the memcache instances don't have a ton of RAM.

If memcache hits its memory limit, does it automatically free up RAM (and hence drop sessions)? Or something else?


Solution

Memcached will use least recently used (LRU) eviction to free up memory. For this reason Memcached, or any cache for that matter, should not be used for long lived sessions (it is fine for short lived sessions).

For long lived session you should use a permanent storage such as a database. If performance is an issue you can emulate write-through caching by caching the session queries (this is what Django's cached_db session storage does for example). I am not aware of any write-through implementation in PHP but it is easy enough to implement.



Answered By - Sascha Trifunovic
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing