本文整理汇总了Python中cache.Cache.store方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.store方法的具体用法?Python Cache.store怎么用?Python Cache.store使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache.Cache
的用法示例。
在下文中一共展示了Cache.store方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import store [as 别名]
def get(url, dest):
"""Get file from <url> and save it to <dest>.
Tries to retrieve <url> from cache, otherwise stores it in
cache following retrieval.
"""
url = urllib.unquote(url)
if url.endswith("/"):
raise Error("illegal url - can't get a directory")
if os.path.isdir(dest):
dest = os.path.join(dest, os.path.basename(url))
else:
if dest.endswith("/"):
raise Error("no such directory: " + dest)
if os.path.lexists(dest):
raise Error("won't overwrite already existing file: " + dest)
cache = Cache()
cached_path = cache.retrieve(url, dest)
if cached_path:
print "* get: retrieved file from cache"
else:
print "* get: retrieving file from network..."
system("curl -L -f %s -o %s" % (mkarg(url), mkarg(dest)))
cached_path = cache.store(url, dest)
return cached_path
示例2: add
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import store [as 别名]
def add(src, url):
"""Add file from <src> to the cache using <url> for future retrieval"""
url = urllib.unquote(url)
if url.endswith("/"):
raise Error("illegal url - can't add a directory")
if not os.path.exists(src):
raise Error("no such file: " + src)
print "* add: storing file in cache..."
cache = Cache()
cached_path = cache.store(url, src)
return cached_path
示例3: Communicator
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import store [as 别名]
class Communicator(object):
'''
Communicator talks to the client and receives commands from the client
in terms of HTTP GET, PUT and DETELE verbs.
Uses the HEAD verb as a control channel signaling the nodes to perform clean ups,
remove dead peers from the key ring etc
see utils package for sample standalone commands
'''
base_file_path = os.path.abspath('.')
#------------------------------------------------------------------------------
# Logging setup
#------------------------------------------------------------------------------
logger = LogHelper.getLogger()
def __init__(self, config):
'''
Constructor
'''
#=======================================================================
# By this time, topology has configured itself based on the config file
# or the defaults
#=======================================================================
self.config = config
self.topology = Topology(config)
self.cache = Cache(reconstruct=self.config.local_reconstruct)
self.logger.info('setup up communicator for node: ' + str(self.config.node_id) + '\n')
def GET(self, key, origin='client'):
if origin == 'client':
self.logger.info("Request from client")
else:
if str(origin) == self.config.node_address:
self.logger.error("Houston, we have a problem. Cycle detected. Have to fail...")
return None
node = self.topology.key_manager.get_node(key)
# for node in node_gen:
self.logger.info("Key requested: " + key)
self.logger.info("Node responsible: " + node)
if node == self.config.node_address: #we are responsible for fetching this key from the cache
return self.cache.fetch(key)
else: #tell our peer to handle this key
return self.topology.instructPeer(node, 'GET', cherrypy.serving.request.path_info) #TODO change faux get/post to auto route
#else:
#===============================================================================
# ideally there should be a for loop at the commented for node in node_gen where node_gen
# is a generator that loops over the set of possible peers
# need to figure out a way to update underlying datastructure over which the generator rotates
# this is against the laws of a generator, so will have to think of some other clever trick.
# This means the node we contacted was down. It was removed from the key ring
# since node_gen is a generator, we will sping until we hit next node who will
# assume responsibility for this key
#===============================================================================
def PUT(self, key, value, origin='client'):
if origin == 'client':
self.logger.info("Request from client")
else:
if str(origin) == self.config.node_address:
self.logger.error("Houston, we have a problem. Cycle detected. Have to fail...")
return None
node = self.topology.key_manager.get_node(key)
# for node in node_gen:
if node == self.config.node_address: #we are responsible for storing this key in the cache
#also forward the request to mirrors
print "mirroring"
self.topology.mirror('PUT', cherrypy.serving.request.path_info)
return self.cache.store(key, value)
else: #tell our peer to handle this key
return self.topology.instructPeer(node, 'PUT', cherrypy.serving.request.path_info) #TODO change faux get/post to auto route
#===============================================================================
# This means the node we contacted was down. It was removed from the key ring
# since node_gen is a generator, we will sping until we hit next node who will
# assume responsibility for this key
#===============================================================================
def DELETE(self, key, origin='client'):
if origin == 'client':
self.logger.info("Request from Client")
else:
if str(origin) == self.config.node_address:
self.logger.error("Houston, we have a problem. Cycle detected. Have to fail...")
#.........这里部分代码省略.........