辋川集

木末芙蓉花,山中发红萼,涧户寂无人,纷纷开且落

By - 陳 思敬

Memcached

Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

Memcached was first developed by Brad Fitzpatrick for his website LiveJournal, on May 22, 2003. It was originally written in Perl, then later rewritten in C by Anatoly Vorobey.
Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.
Quick Example

function get_foo(foo_id)
    foo = memcached_get("foo:" . foo_id)
    return foo if defined foo
    foo = fetch_foo_from_database(foo_id)
    memcached_set("foo:" . foo_id, foo)
    return foo
end

Installation

wget http://memcached.org/latest
tar -zxvf memcached-1.x.x.tar.gz
cd memcached-1.x.x
./configure && make && make test && sudo make install

System

touch /etc/init.d/memcached
chmod +x /etc/init.d/memcached

 

#!/bin/bash
# v.0.0.1
# create by snowolf at 2012.5.25
#
# memcached  - This shell script takes care of starting and stopping memcached.
#
# chkconfig: - 90 10
# description: Memcache provides fast memory based storage.
# processname: memcached
memcached_path="/usr/local/bin/memcached"
memcached_pid="/var/run/memcached.pid"
memcached_memory="1024"
# Source function library.
. /etc/rc.d/init.d/functions
[ -x $memcached_path ] || exit 0
RETVAL=0
prog="memcached"
# Start daemons.
start() {
    if [ -e $memcached_pid -a ! -z $memcached_pid ];then
        echo $prog" already running...."
        exit 1
    fi
    echo -n $"Starting $prog "
    # Single instance for all caches
    $memcached_path -m $memcached_memory -l 0.0.0.0 -p 11211 -u root -d -P $memcached_pid
    RETVAL=$?
    [ $RETVAL -eq 0 ] && {
        touch /var/lock/subsys/$prog
        success $"$prog"
    }
    echo
    return $RETVAL
}
# Stop daemons.
stop() {
    echo -n $"Stopping $prog "
    killproc -d 10 $memcached_path
    echo
    [ $RETVAL = 0 ] && rm -f $memcached_pid /var/lock/subsys/$prog
    RETVAL=$?
    return $RETVAL
}
# See how we were called.
case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        status)
            status $prog
            RETVAL=$?
            ;;
        restart)
            stop
            start
            ;;
        *)
            echo $"Usage: $0 {start|stop|status|restart}"
            exit 1
esac
exit $RETVAL

Java Client
GitHub last update 2 years ago.

4 thoughts on “Memcached

陈自新 December 15, 2014 at 12:49 pm

Mac 安装推荐使用 Homebrew
Homebrew 会将套件安装到独立目录,并将文件软链接至 /usr/local 。
install

$ brew install wget

simulate

$ cd /usr/local
$ find Cellar
Cellar/wget/1.15
Cellar/wget/1.15/bin/wget
Cellar/wget/1.15/share/man/man1/wget.1
$ ls -l bin
bin/wget -> ../Cellar/wget/1.15/bin/wget

Reply

陈自新 December 15, 2014 at 1:10 pm

安装命令来自: CSDN,请触类旁通。

Reply

陈自新 December 15, 2014 at 2:31 pm

memcached-1.4.21.tar.gz
memcached-win32-1.4.4-14.zip
memcached-win64-1.4.4-14.zip
java_memcached-release_2.0.1.zip

Reply

陈自新 December 18, 2014 at 10:07 am

参考:Turbocharge Your Website With Memcached

Reply

Leave a Reply

Your email address will not be published.
*
*