CL-MEMCACHED - Common Lisp interface to the memcached object caching system.


 

Abstract

CL-MEMCACHED is a Simple, Fast, Thread-Safe library to interface with the memcached object caching system. It implements the Memcached TEXT protocol.

Tested on SBCL, CCL, CMUCL.


memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

Danga Interactive developed memcached to enhance the speed of LiveJournal.com, a site which was already doing 20 million+ dynamic page views per day for 1 million users with a bunch of webservers and a bunch of database servers. memcached dropped the database load to almost nothing, yielding faster page load times for users, better resource utilization, and faster access to the databases on a memcache miss.

The code comes with a MIT-style license so you can basically do with it whatever you want.

Project page: cl-memcached.

Lists

Please post issues on the github page.


 

Contents

  1. Download
  2. The CL-MEMCACHED dictionary
    1. *mc-default-encoding*
    2. *mc-use-pool*
    3. *memcache*
    4. make-memcache
    5. mc-add
    6. mc-append
    7. mc-bytes
    8. mc-cas
    9. mc-cas-unique
    10. mc-data
    11. mc-data-raw
    12. mc-decr
    13. mc-del
    14. mc-flags
    15. mc-flush-all
    16. mc-get
    17. mc-get+
    18. mc-get-value
    19. mc-incr
    20. mc-key
    21. mc-prepend
    22. mc-replace
    23. mc-set
    24. mc-stats
    25. mc-stats-summary
    26. mc-store
    27. mc-touch
    28. mc-verbosity
    29. mc-version
  3. Acknowledgements

 

Download

CL-MEMCACHED together with this documentation can be downloaded from cl-memcached. The current version is 1.0.0.

Install using quicklisp : (ql:quickload 'cl-memcached)


 

Example Usage

CL-USER> (require 'cl-memcached)
NIL

CL-MEMCACHED> (in-package :cl-memcached)
#<PACKAGE "CL-MEMCACHED">

CL-MEMCACHED> (setf *memcache* (make-memcache))
#<MEMCACHED-SERVER Name:Memcache IP:127.0.0.1 Port:11211 >

CL-MEMCACHED> (mc-quick-test "foo" "bar")
Success SET
Success GET
NIL

CL-MEMCACHED> (mc-set "t1" "oooooooooooooooooooooo")
STORED
:INTERNAL

CL-MEMCACHED> (mc-get+ "t1")
#<MEMCACHED-RESPONSE Key:t1 Data-Length:22 >

CL-MEMCACHED> (describe *)
#<MEMCACHED-RESPONSE Key:t1 Data-Length:22 >
  [structure-object]

Slots with :INSTANCE allocation:
  KEY         = "t1"
  FLAGS       = "0"
  BYTES       = 22
  CAS-UNIQUE  = NIL
  DATA-RAW    = #(111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111..
; No value

CL-MEMCACHED> (mc-data (mc-get+ "t1"))
"oooooooooooooooooooooo"

CL-MEMCACHED> (mc-get-value "t1")
"oooooooooooooooooooooo"

CL-MEMCACHED> (mc-set "t2" "0")
STORED
:INTERNAL

CL-MEMCACHED> (mc-incr "t3")
NOT_FOUND

CL-MEMCACHED> (mc-incr "t2")
1
1

CL-MEMCACHED> (mc-incr "t2")
2
1

CL-MEMCACHED> (mc-decr "t2")
1
1


 

The CL-MEMCACHED dictionary


[Special variable]
*mc-default-encoding*


Default encoding


[Special variable]
*mc-use-pool*


Default value for the MC-USE-POOL keyword parameter in memcached functions


[Special variable]
*memcache*


Represents a particular Memcached server


[Function]
make-memcache &key ip port name pool-size => result


Creates an instance of class MEMCACHE which represents a memcached server


[Function]
mc-add key data &key memcache timeout flags noreply external-format mc-use-pool => result



[Function]
mc-append key data &key memcache timeout flags noreply external-format mc-use-pool => result



[Function]
mc-bytes instance => result


Return whether debug-block represents elsewhere code.


[Function]
mc-cas key data cas-unique &key memcache timeout flags noreply external-format mc-use-pool => result


Check And Set Operation : Store this data buy only if no one else has updated since I last fetched it


[Function]
mc-cas-unique instance => result


Return whether debug-block represents elsewhere code.


[Function]
mc-data response &key external-format => result



[Function]
mc-data-raw instance => result


Return whether debug-block represents elsewhere code.


[Function]
mc-decr key &key value noreply memcache mc-use-pool => result



[Function]
mc-del key &key noreply memcache mc-use-pool => result



[Function]
mc-flags instance => result


Return whether debug-block represents elsewhere code.


[Function]
mc-flush-all &key delay noreply memcache mc-use-pool => result



[Function]
mc-get keys-list &key memcache mc-use-pool => result



[Function]
mc-get+ key-or-list-of-keys &key memcache mc-use-pool => result


Takes a key or a list of keys are returns a list of MEMCACHE-RESPONSE structures


[Function]
mc-get-value key &key memcache mc-use-pool external-format => result


A utility macro to query a key and return a external-format decoded string


[Function]
mc-incr key &key value noreply memcache mc-use-pool => result



[Function]
mc-key instance => result


Return whether debug-block represents elsewhere code.


[Function]
mc-prepend key data &key memcache timeout flags noreply external-format mc-use-pool => result



[Function]
mc-replace key data &key memcache timeout flags noreply external-format mc-use-pool => result



[Function]
mc-set key data &key memcache timeout flags noreply external-format mc-use-pool => result



[Function]
mc-stats &key memcache mc-use-pool => result


Returns an ALIST of stats data from memcached server


[Function]
mc-stats-summary &key memcache => result



[Function]
mc-store key data &key memcache command timeout flags noreply cas-unique mc-use-pool => result


Stores data in the memcached server using the :command command. KEY => KEY by which the DATA is stored. this is of type SIMPLE-STRING DATA => DATA to be stored into the cache. DATA has to be a sequence of TYPE (UNSIGNED-BYTE 8). MEMCACHE => A structure representing the MEMCACHE we want to use. command => The storage command we want to use. There are 5 available : set, add, replace, append & prepend. timeout => The time in seconds when this data expires. 0 is never expire. flags => noreply => server does not send a reply mc-use-pool => use connection from pool (much faster for load) response : - 'STOREDrn', to indicate success. - 'NOT_STOREDrn' to indicate the data was not stored, but not because of an error. This normally means that the condition for an 'add' or a 'replace' command wasn't met. - 'EXISTSrn' to indicate that the item you are trying to store with a 'cas' command has been modified since you last fetched it. - 'NOT_FOUNDrn' to indicate that the item you are trying to store with a 'cas' command did not exist.


[Function]
mc-touch key expiry-time &key noreply memcache mc-use-pool => result



[Function]
mc-verbosity &key level noreply memcache mc-use-pool => result



[Function]
mc-version &key memcache mc-use-pool => result



 

Benchmark

Host OS : OSX 10.8.4 Dataset: 1024 bytes (1kb) text string. Repeat 10000 times.

implementationSET without poolSET with poolGET without poolGET with pool
SBCL 1.1.104.9420.7134.9050.690
CCL 1.9-r157594.7110.8474.5060.648
CMUCL 20D Unicode4.4600.9704.2900.810
Dalli on Ruby 1.90.9571.033

When we do not use the pool we make a new socket connection every time.

The Ruby 'dalli' client, which implements the binary protocol, uses the same socket (I think) so this should be comparable with our with-pool.


 

Author

Abhijit 'quasi' Rao

This documentation was prepared with DOCUMENTATION-TEMPLATE.

$Header: /usr/local/cvsrep/documentation-template/output.lisp,v 1.18 2013-01-11 13:45:29 edi Exp $

quasiLabs