Spring Consolidation memcached Considerations-poolname

Source: Internet
Author: User
Tags memcached

Memecached Javaclient must initialize the Sockiopool before it is used, which has only one protected construction method, so the external need to use the static method provided by it getinstance to obtain the Sockiopool instance. The GetInstance method allows incoming poolname to indicate the Sockiopool name. Sockiopool itself is only as a Schoonersockiopool proxy class, Schoonersockiopool maintains a connection pool map, where poolname as key, Pool instance as a value. So when you use spring to consolidate memcacheds, if you indicate poolname in the spring configuration file, you need to specify poolname in its constructor when initializing Memecachedclient. If no poolname is declared, memechachedclient or gets the pool instance named default.

For the following configuration, you must pass in the poolname when Memechacedclient is instantiated. Otherwise, data operations or data operations will not be available.

Spring configuration file, which declares Sockiopool, because the class is constructed with a protected type and cannot be accessed directly, you need to use the factory method getinstance () to get the example, note: here < The constructor-arg> label is not an argument for a constructor, but rather as a parameter to the factory method getinstance (), indicating that poolname is Memcache

<bean id= "Memcache" class= "Com.whalin.MemCached.SockIOPool" factory-method= "getinstance" Initialize "destroy-method=" ShutDown "><constructor-arg> <value>memcache</value> </constructor-arg><property name= "Servers" > <list> <value>${memcache.server}</value> </list> </ property> <property name= "Initconn" > <value>${memcache.initConn}</value> </property> & Lt;property name= "Minconn" > <value>${memcache.minConn}</value> </property> <property name= "
			Maxconn "> <value>${memcache.maxConn}</value> </property> <property name=" Maintsleep "> <value>${memcache.maintSleep}</value> </property> <property name= "Nagle" > <value>${m emcache.nagle}</value> </property> <property name= "Socketto" > <value>${memcache.socketto}& Lt;/value> </property> </bean>
When you use Memcachedclient to access memchached, you must indicate that poolname is memcache (default defaults, but default is not configured in the configuration file)
Memcachedclient memcachedclient = new Memcachedclient ("Memcache");
Memcachedclient.set ("name", "simple");
System.out.println (Memcachedclient.get ("name"));
When Memcachedclient is instantiated here, the parameter ' Memcache ' class must be passed in to indicate the pool instance name, otherwise there will be no error at insertion, but the read value will always be null

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.