1) Install Memcache service End
sudo apt-get install memcached
After installing the Memcache server, we need to start the service:
Memcached-d-M 128-p 11111-u Root
Here you need to explain the startup parameters for the memcached service:
-P Listening Port
The IP address of the-l connection, the default is native
-D Start memcached service
-D Restart Restart memcached service
-D Stop|shutdown shut down the running memcached service
-D Install installation memcached service
-d Uninstall Uninstall memcached service
-U Run as (only valid when run as root)
-m maximum memory usage, in MB. Default 64MB
-Returns an error when M memory is exhausted instead of deleting the item
-C Maximum Simultaneous connection number, default is 1024
-F Block size growth factor, default is 1.25-n minimum allocation space, key+value+flags default is 48
-H Display Help
See if success was established
Telnet test memcached
Telnet 192.168.1.2 11211
Trying 192.168.1.2 ...
Connected to 192.168.1.2.
Escape character is ' ^] '
View version
Version
...
For a status query on the memcached cache service, you can first telnet to the service: Telnet 127.0.0.1 11211, and then use the Stats command to view the status of the cached service, returning the following data:
time:1255537291 server's current UNIX timestamp
total_items:54 total number of items stored since server startup
Number of connection constructs that the CONNECTION_STRUCTURES:19 server assigns
version:1.2.6 memcache Version
limit_maxbytes:67108864 amount of memory allocated to Memcache (bytes)
cmd_get:1645 get Command (gets) the total number of requests
evictions:0 the number of items that are deleted to get free memory (the space allocated to Memcache should be full
To remove old items to get space allocated to new items)
TOTAL_CONNECTIONS:19 number of connections that have been opened since the server was started
bytes:248723 the number of bytes consumed by the current server storage items
Threads:1 the current number of threads
get_misses:82 Total missed Hits
POINTER_SIZE:32 the current operating system's pointer size (32-bit system is typically 32bit)
bytes_read:490982 Total Read bytes (number of bytes requested)
Number of seconds the uptime:161 server has been running
Curr_connections:18 the number of connections currently open
pid:2816 Memcache server's process ID
bytes_written:16517259 Total Bytes Sent (result bytes)
Total hit times of get_hits:1563
cmd_set:54 set Command (save) number of total requests
Number of items currently stored by the CURR_ITEMS:28 server
Ok, installation memcached1.4.5 successful.
Initialization: Memcache
Java code static {string[] ServerList = {"Server1.com:port", "Server2.com:port"}; Sockiopool pool = sockiopool.getinstance (); Pool.setservers (serverlist); Pool.initialize (); }
To create a client object:
Java code memcachedclient MC = new Memcachedclient ();
To create a cache:
Java code memcachedclient MC = new Memcachedclient (); String key = "CacheKey1"; Object value = Someclass.getobject (); Mc.set (key, value);
Delete a cache via key:
Java code memcachedclient MC = new Memcachedclient (); String key = "CacheKey1"; Mc.delete (key);
Gets the cached object via key:
Java code memcachedclient MC = new Memcachedclient (); String key = "key"; Object value = Mc.get (key);
To get more than one cache object:
Java code