Memcache not working?

0 views
Skip to first unread message

Tony Speer

unread,
Sep 4, 2008, 9:45:48 PM9/4/08
to Google App Engine
I'm trying to use memcache and it seems to be working on my dev
server. I'm caching three thing and only two of them stay cached. Here
is my code. mcount is the one thats not working.

#this works
wbcount = memcache.get("wbcount")
if wbcount is None:
debug("Caching wbcount")
wbcount = 0
memcache.add(key="wbcount", value=wbcount, time=60 * 60)
v["wbcount"] = wbcount


#this does not
mcount = memcache.get("mcount")
if mcount is None:
debug("Caching mcount") # I keep seeing this in the logs!!!!!
<<<
mcount = museum.all().count()
memcache.add(key="mcount", value=mcount, time=60 * 60)
v["mcount"] = mcount

#this works
ucount = memcache.get("ucount")
if ucount is None:
debug("Caching ucount")
ucount = ruser.all().count()
memcache.add(key="ucount", value=ucount, time=60 * 60)
v["ucount"] = ucount

Am I doing anything wrong?

theo

unread,
Sep 5, 2008, 1:12:11 PM9/5/08
to Google App Engine
are you using memcache.delete at all?

Wooble

unread,
Sep 5, 2008, 4:03:10 PM9/5/08
to Google App Engine
I believe memcache.add works asynchronously (the docs say it will
never block, and I assume it must take some non-zero time to actually
add anything to the cache), so an add followed immediately by a get
can be too fast for the get to return anything. I don't believe
memcache is intended to work in realtime, and it's probably not a good
idea for a single invocation to need to fetch anything from the cache
that it put there itself; as fast as memcache is you'll always get
better performance from just storing the value in a local variable as
well as in the cache.

In the intended use of memcache (difference instances of your
application reading and writing the same cache), you'll see
practically no lag since the time it takes to add something to the
cache is incredibly unlikely to be longer than the time between
requests even if it's longer than the time between executing two
statements in a single python script.
Reply all
Reply to author
Forward
0 new messages