本文整理汇总了Python中cache.Cache.ram方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.ram方法的具体用法?Python Cache.ram怎么用?Python Cache.ram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache.Cache
的用法示例。
在下文中一共展示了Cache.ram方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCacheWithPrefix
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import ram [as 别名]
def testCacheWithPrefix(self):
s = Storage({'application': 'admin',
'folder': 'applications/admin'})
cache = Cache(s)
prefix = cache.with_prefix(cache.ram,'prefix')
self.assertEqual(prefix('a', lambda: 1, 0), 1)
self.assertEqual(prefix('a', lambda: 2, 100), 1)
self.assertEqual(cache.ram('prefixa', lambda: 2, 100), 1)
示例2: copystream_progress
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import ram [as 别名]
def copystream_progress(request, chunk_size= 10**5):
"""
copies request.env.wsgi_input into request.body
and stores progress upload status in cache.ram
X-Progress-ID:length and X-Progress-ID:uploaded
"""
env = request.env
if not env.content_length:
return cStringIO.StringIO()
source = env.wsgi_input
try:
size = int(env.content_length)
except ValueError:
raise HTTP(400,"Invalid Content-Length header")
dest = tempfile.TemporaryFile()
if not 'X-Progress-ID' in request.vars:
copystream(source, dest, size, chunk_size)
return dest
cache_key = 'X-Progress-ID:'+request.vars['X-Progress-ID']
cache = Cache(request)
cache.ram(cache_key+':length', lambda: size, 0)
cache.ram(cache_key+':uploaded', lambda: 0, 0)
while size > 0:
if size < chunk_size:
data = source.read(size)
cache.ram.increment(cache_key+':uploaded', size)
else:
data = source.read(chunk_size)
cache.ram.increment(cache_key+':uploaded', chunk_size)
length = len(data)
if length > size:
(data, length) = (data[:size], size)
size -= length
if length == 0:
break
dest.write(data)
if length < chunk_size:
break
dest.seek(0)
cache.ram(cache_key+':length', None)
cache.ram(cache_key+':uploaded', None)
return dest
示例3: copystream_progress
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import ram [as 别名]
def copystream_progress(request, chunk_size=10 ** 5):
"""
copies request.env.wsgi_input into request.body
and stores progress upload status in cache.ram
X-Progress-ID:length and X-Progress-ID:uploaded
"""
env = request.env
if not env.content_length:
return cStringIO.StringIO()
source = env.wsgi_input
size = int(env.content_length)
dest = tempfile.TemporaryFile()
if not "X-Progress-ID" in request.vars:
copystream(source, dest, size, chunk_size)
return dest
cache_key = "X-Progress-ID:" + request.vars["X-Progress-ID"]
cache = Cache(request)
cache.ram(cache_key + ":length", lambda: size, 0)
cache.ram(cache_key + ":uploaded", lambda: 0, 0)
while size > 0:
if size < chunk_size:
data = source.read(size)
cache.ram.increment(cache_key + ":uploaded", size)
else:
data = source.read(chunk_size)
cache.ram.increment(cache_key + ":uploaded", chunk_size)
length = len(data)
if length > size:
(data, length) = (data[:size], size)
size -= length
if length == 0:
break
dest.write(data)
if length < chunk_size:
break
dest.seek(0)
cache.ram(cache_key + ":length", None)
cache.ram(cache_key + ":uploaded", None)
return dest