In the current speech system, frequent I/O operations are required. In order to cope with the possible high-concurrency access in the future, a cache mechanism is planned.
Among the many caches, ehcache has a good reputation. I have also written an article about the use of ehcache:
Http://lcllcl987.javaeye.com/blog/222693
However, ehcache is not a distributed cache solution.
Therefore, memcached is selected for the primary election:
Http://www.danga.com/memcached/
The installation of memcached is handed over to Google.
The following is the JAVA Implementation of two memcached clients:
Http://www.whalin.com/memcached/
Http://code.google.com/p/spymemcached/
To
Http://www.whalin.com/memcached/
For example, its documentation is good and I will not talk about it much. Test is as follows:
- Package Co. cache;
- Import com. danga. memcached. memcachedclient;
- Import com. danga. memcached. sockiopool;
- Public class mymemcachedclient
- {
- // Create a static client as most installonly need
- // A single instance
- Private Static memcachedclient = new memcachedclient ();
- // Set up connection pool once at class load
- Static
- {
- // Server list and weights
- String [] servers = {"192.168.0.55: 11211 "};
- Integer [] weights = {3 };
- // Grab an instance of our connection pool
- Sockiopool pool = sockiopool. getinstance ();
- // Set the servers and the weights
- Pool. setservers (servers );
- Pool. setweights (weights );
- // Set some basic pool settings
- // 5 initial, 5 min, and 250 Max Conns
- // And set the max idle time for a Conn
- // To 6 hours
- Pool. setinitconn (5 );
- Pool. setminconn (5 );
- Pool. setmaxconn (250 );
- Pool. setmaxidle (1000*60*60*6 );
- // Set the sleep for the Maint thread
- // It will wake up every X seconds and
- // Maintain the pool size
- Pool. setmaintsleep (30 );
- // Set some TCP settings
- // Disable Nagle
- // Set the read timeout to 3 secs
- // And don't set a connect timeout
- Pool. setnagle (false );
- Pool. setsocketto (3000 );
- Pool. setsocketconnectto (0 );
- // Initialize the connection pool
- Pool. initialize ();
- // Lets set some compression on for the client
- // Compress anything larger than 64 K
- Memcachedclient. setcompressenable (true );
- Memcachedclient. setcompressthreshold (64*1024 );
- }
- Public static memcachedclient getmemcachedclient ()
- {
- Return memcachedclient;
- }
- // From here on down, you can call any of the client CILS
- Public static void examples ()
- {
- Memcachedclient. Set ("foo", "this is a test string ");
- String bar = (string) memcachedclient. Get ("foo ");
- }
- Public static void main (string [] ARGs)
- {
- Mymemcachedclient. getmemcachedclient (). Set ("foo", "this is a test string .");
- String bar = (string) mymemcachedclient. getmemcachedclient (). Get ("foo ");
- System. Out. println (bar );
- }
- }
- Unlike ehcache, memcached seems to only use the LRU algorithm to deal with the situation where the cache is full.
ZZ: http://blog.csdn.net/lcllcl987/archive/2008/11/03/3209987.aspx