skip to navigation
skip to content

Not Logged In

mockcache 1.0.1

The Python dictionary-based mock memcached client library.

The Python dictionary-based mock memcached client library. It does not
connect to any memcached server, but keeps a dictionary and stores every cache
into there internally. It is a just emulated API of memcached client only for
tests. It implements expiration also. NOT THREAD-SAFE.

try:
import memcache
except ImportError:
import warnings
import mockcache as memcache
warnings.warn("imported mockcache instead of memcache; cannot find "
"memcache module")

mc = memcache.Client(["127.0.0.1:11211"])

This module and other memcached client libraries have the same behavior.

>>> from mockcache import Client
>>> mc = Client()
>>> mc
<mockcache.client {}="">
>>> mc.get("a")
>>> mc.get("a") is None
True
>>> mc.set("a", "1234")
1
>>> mc.get("a")
'1234'
>>> mc
<mockcache.client {'a':="" ('1234',="" none)}="">
>>> mc.add("a", "1111")
0
>>> mc.get("a")
'1234'
>>> mc
<mockcache.client {'a':="" ('1234',="" none)}="">
>>> mc.replace("a", "2222")
1
>>> mc.get("a")
'2222'
>>> mc
<mockcache.client {'a':="" ('2222',="" none)}="">
>>> mc.append("a", "3")
1
>>> mc.get("a")
'22223'
>>> mc
<mockcache.client {'a':="" ('22223',="" none)}="">
>>> mc.prepend("a", "1")
1
>>> mc.get("a")
'122223'
>>> mc
<mockcache.client {'a':="" ('122223',="" none)}="">
>>> mc.incr("a")
122224
>>> mc.get("a")
122224
>>> mc
<mockcache.client {'a':="" (122224,="" none)}="">
>>> mc.incr("a", 10)
122234
>>> mc.get("a")
122234
>>> mc
<mockcache.client {'a':="" (122234,="" none)}="">
>>> mc.decr("a")
122233
>>> mc.get("a")
122233
>>> mc
<mockcache.client {'a':="" (122233,="" none)}="">
>>> mc.decr("a", 5)
122228
>>> mc.get("a")
122228
>>> mc
<mockcache.client {'a':="" (122228,="" none)}="">
>>> mc.replace("b", "value")
0
>>> mc.get("b")
>>> mc.get("b") is None
True
>>> mc
<mockcache.client {'a':="" (122228,="" none)}="">
>>> mc.add("b", "value", 5)
1
>>> mc.get("b")
'value'
>>> mc # doctest: +ELLIPSIS
<mockcache.client {'a':="" (122228,="" none),="" 'b':="" ('value',="" ...)}="">
>>> import time
>>> time.sleep(6)
>>> mc.get("b")
>>> mc.get("b") is None
True
>>> mc
<mockcache.client {'a':="" (122228,="" none)}="">
>>> mc.set("c", "value")
1
>>> mc.get_multi(["a", "b", "c"])
{'a': 122228, 'c': 'value'}
>>> mc.delete("a")
1
>>> mc.get("a") is None
True  
File Type Py Version Uploaded on Size
mockcache-1.0.1.tar.gz (md5) Source 2010-05-06 3KB
  • Downloads (All Versions):
  • 39 downloads in the last day
  • 210 downloads in the last week
  • 587 downloads in the last month