if the Session is stored with memcached, the user will not be able to log in or be kicked off when the memcached cluster fails (such as a memory overflow) or maintenance (such as upgrading, increasing, or reducing the server).
Second, the memcached recovery mechanism may cause the user to drop the line without reason. Because Memcached uses the least recently used (LRU) algorithm to reclaim the cache. This means that if all sessions are roughly the same size, they will be divided into two or three slab classes. All other data of roughly the same size will be placed in the same slab with the Session contention storage space. Once the slab is full, even if there is room in the larger slab, the data will be collected instead of being put into the larger slab ... In a particular slab, the oldest user of the Session will be dropped. The user will start to randomly drop the line, and worst of all, you probably won't even notice it until the user starts complaining ... In addition, if new data is added to the session, then the session becomes larger and may lead to a drop-off problem.
It was proposed to use separate memcached caches for Session and other data respectively. However, because Memcached's LRU algorithm is local , that approach not only leads to low memory usage, but also eliminates the risk that users will be randomly dropped due to Session recycling.
Note: memcached is a system designed to cache data instead of storing data, so it should not be used to store the Session.
If you really want to use memcached to improve the Session read speed, then you can draw on the Norkūnas proposed Memcached+rdbms (in some cases, NoSQL can) mode:
1, when the user login, the Session "set" to memcached, and write to the database;
2. Add a field to the session to identify when the session was last written to the database;
3, each page load, the priority from memcached read Session, followed by reading from the database;
4, after each load N pages or Y minutes, the Session is written to the database again;
5. Get the expired Session from the database, and get the latest data from memcached first.
Why can't I store Session with memcached