简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM