google(六)memcached service

本文介绍了如何使用Google App Engine的Memcache API进行数据缓存操作,包括添加、设置及原子递增等基本操作,并提供了一段典型的Memcache请求伪代码示例。
google(六)memcached service

document
http://code.google.com/intl/en/appengine/docs/python/memcache/

Memcache Python API Overview - Caching Data in Python
from google.appengine.api import memcache

#Add a value if it doesn't exist in the cache, with a cache expiration of 1 hour
memcache.add(key="test_key_001",value="test_value_001",time=3600)

#Set serveral values, overwriting any existing values for these keys.
memcache.set_multi({"key_001":"value_001",
"key_002":"value_002},
key_prefix="multi_",time=3600)

# atomically increment an integer value.
memcache.set(key="counter",0)
memcache.incr("counter")
memcache.incr("counter")

Using Memcached - The Memcache Pattern

The pseudocode below represents a typical memcache request:

def get_data():
data=memcache.get("key")
if data is not None:
return data
else:
data = self.query_for_data()
memcache.add("key",data,60)
return data

log system code piece:
import logging

logging.getLogger().setLevel(logging.DEBUG)

if not memcache.add("greetings",greetings,10):
logging.error("Memcache set failed.")

if not memcache.decr("online_users"):
logging.error("decrease online_users in memcache failed!")

API references book:
http://code.google.com/intl/en/appengine/docs/python/memcache/clientclass.html
http://code.google.com/intl/en/appengine/docs/python/memcache/functions.html


error message from the console:
INFO 2010-09-27 03:40:09,350 dev_appserver.py:3275] "GET /favicon.ico/ HTTP/1.1" 404 -
answer is here:
http://www.favicon.com/
get one image file from here http://www.favicon.com/favicon.ico,
add this to your app.yaml
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: static/images/favicon.ico
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值