The main purpose of using memcached in the project is to reduce the number of database accesses by caching database query results, thus increasing the speed and scalability of dynamic, database-driven Web sites. Memcached is a high-performance distributed memory object caching system based on a hashmap that stores key/value pairs.
Implement your cache class
Import net.spy.memcached.MemcachedClient;
Import Org.apache.commons.logging.Log;
Import Org.apache.commons.logging.LogFactory;
Public final class Memcached implements cache{
Public Object get (String key) {
Object result = null;
try {
result = Memcachedclient.get (key);
} catch (Exception e) {
Log.error ("Failed to get" + key + "' from cache.", e);
}
return result;
}
public void put (String key, Object value) {
Put (key, value, ExpiredTime);
}
public void put (String key, Object value, int expiredtime) {
try {
Memcachedclient.set (Key, ExpiredTime, value);
} catch (Exception e) {
Log.error ("Failed to put" + key + "into cache.", e);
}
}
public void Remove (String key) {
try {
Memcachedclient.delete (key);
} catch (Exception e) {
Log.error ("Failed to remove Cache" + key + "'.", e);
}
}
public void setexpiredtime (int expiredtime) {
This.expiredtime = ExpiredTime;
}
public void Setmemcachedclient (Memcachedclient memcachedclient) {
This.memcachedclient = memcachedclient;
}
Private Memcachedclient memcachedclient;
private int expiredtime = 60 * 120;
Private static final Log log = Logfactory.getlog (Memcached.class);
}
Configuring cache-related class relationships and attributes in ApplicationContext
The role of specific properties can be referred to the official note: https://code.google.com/p/spymemcached/wiki/SpringIntegration
Reference: http://blog.sina.com.cn/s/blog_60e4b3a90101c1po.html
Deploying in Java projects using memcached[to]