Created
February 18, 2014 19:53
-
-
Save lost-theory/9078654 to your computer and use it in GitHub Desktop.
dogpile.cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Starting a reader while a few dog_writer.py processes are running in the background: | |
$ bin/python dog_reader.py | |
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? | |
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? 190 172 159 ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? 732 ??? | |
??? ??? ??? ??? ??? 190 ??? ??? ??? ??? 190 172 190 ??? ??? ??? 172 ??? ??? 732 ??? ??? ??? ??? ??? ??? ??? ??? 732 159 | |
??? 172 ??? ??? 159 172 ??? ??? ??? ??? 190 172 190 ??? ??? ??? 172 159 ??? 732 ??? ??? ??? 172 732 ??? ??? 732 732 159 | |
172 172 ??? ??? 159 172 ??? ??? 172 ??? 190 172 190 159 ??? ??? 172 159 ??? 732 ??? ??? ??? 732 732 ??? 172 732 732 159 | |
172 732 ??? ??? 159 172 ??? ??? 172 ??? 190 172 190 159 159 ??? 172 732 ??? 732 ??? ??? ??? 190 732 732 172 732 732 159 | |
172 190 ??? ??? 159 172 ??? ??? 172 ??? 190 172 190 732 190 ??? 159 732 ??? 732 ??? 159 159 190 172 732 172 732 732 159 | |
...then kill the dog_writer.py processes and wait 30 seconds... | |
159 ??? ??? ??? 159 732 159 732 732 732 159 190 190 159 ??? 159 732 159 ??? ??? 172 172 732 159 159 172 172 172 159 172 | |
159 ??? ??? ??? 159 732 159 732 732 732 159 190 190 159 ??? 159 732 159 ??? ??? 172 172 732 ??? 159 172 172 172 159 172 | |
??? ??? ??? ??? 159 732 159 732 732 732 159 190 190 159 ??? 159 732 159 ??? ??? 172 ??? 732 ??? ??? 172 172 172 159 172 | |
??? ??? ??? ??? ??? 732 159 ??? ??? 732 159 190 190 159 ??? 159 732 159 ??? ??? 172 ??? 732 ??? ??? 172 172 172 159 172 | |
??? ??? ??? ??? ??? 732 159 ??? ??? 732 159 190 ??? 159 ??? 159 732 ??? ??? ??? ??? ??? 732 ??? ??? ??? 172 ??? 159 172 | |
??? ??? ??? ??? ??? 732 159 ??? ??? 732 ??? 190 ??? ??? ??? 159 ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? 172 | |
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? | |
Everything has expired! | |
''' | |
import time | |
from dogpile.cache import make_region | |
from dogpile.cache.api import NO_VALUE | |
r = make_region().configure( | |
'dogpile.cache.dbm', | |
expiration_time=30, | |
arguments={'filename': '/tmp/blah.dbm'} | |
) | |
def display(v): | |
if v is NO_VALUE: | |
return "???" | |
return v | |
if __name__ == "__main__": | |
while True: | |
for i in range(1,30): | |
print display(r.get(str(i))), | |
print "" | |
time.sleep(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Start a bunch of writers in parallel: | |
$ for i in {0..10}; do bin/python dog_writer.py & done; | |
Stop them: | |
$ pkill -f python.*dog_writer | |
''' | |
import time | |
import random | |
from dogpile.cache import make_region | |
from dog_reader import r | |
if __name__ == "__main__": | |
uid = random.randint(100, 999) | |
while True: | |
args = (str(random.randint(1,30)), uid) | |
print args | |
r.set(*args) | |
time.sleep(random.random()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment