Deploying in Java projects using memcached[to]

Source: Internet
Author: User
Tags log log

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.