Session transfer (using the Filter method to store the Session with Memcached)

I saw the post "Extending Tomcat 6.x and using memcached to store session information" in the past two days. It is very interesting. I also had the idea of ​​using Memcached to manage sessions before, but I haven't practiced it. I have practiced it in the past two days. It's a good way to extend Tomcat, but I prefer to use Resin, so let's implement a general module. You can download the attachment, which contains the entire project. If you want to use it, refer to web.xml and add Filter to your own project. Okay, the memcached.properties file is the configuration file of memcached, just put it in your classes root. 

Pay attention to several problems in the use process: 
1. The memcache should be large enough within a certain period of time, so that the user session will not be cleared from the cache. 
2. If the session read is much more than the write, you can add an Oscache before the memcache to reduce the read operation of the memcache, thereby reducing the network overhead and improving the performance (this is also proposed by codeutil, and I have implemented it myself. , but without adding the source code, you can do it yourself). 
3. If there are a lot of users, you can use the memcached group, insert the hashCode in the set method, and insert it into a memcached server. 

In fact, memcached is used for session management. I think memcached is used as a relatively persistent memory tool. You can use it have a test.

 

Because the session is obtained from the cache, not from a server, so there is no transfer. 

 

It can be seen from the above code that getsession, the service container will call the method inside the container to obtain the cookieid of the client, and then call its own getsession comparison (the work that the server will do by itself). As for the cache, as long as the cache synchronization is consistent, the comparison will definitely pass, thus bypassing the comparison mechanism, and it will be released later (so the copied session does not need to be synchronized to the new service)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326358243&siteId=291194637