本文整理汇总了Python中cache.Cache.expireCache方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.expireCache方法的具体用法?Python Cache.expireCache怎么用?Python Cache.expireCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache.Cache
的用法示例。
在下文中一共展示了Cache.expireCache方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CachingClcInterface
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import expireCache [as 别名]
#.........这里部分代码省略.........
try:
self.zones.values = self.clc.get_all_zones()
Threads.instance().invokeCallback(callback, Response(data=self.zones.values))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def get_all_images(self, owners, callback):
if self.images.isCacheStale():
Threads.instance().runThread(self.__get_all_images_cb__, ({'owners': owners}, callback))
else:
callback(Response(data=self.images.values))
def __get_all_images_cb__(self, kwargs, callback):
try:
self.images.values = self.clc.get_all_images(kwargs['owners'])
Threads.instance().invokeCallback(callback, Response(data=self.images.values))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
# returns list of image attributes
def get_image_attribute(self, image_id, attribute):
Threads.instance().runThread(self.__get_image_attribute_cb__,
({'image_id':image_id, 'attribute':attribute}, callback))
def __get_image_attribute_cb__(self, kwargs, callback):
try:
ret = self.clc.get_image_attribute(kwargs['image_id'], kwargs['attribute'])
Threads.instance().invokeCallback(callback, Response(data=ret))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
# returns True if successful
def modify_image_attribute(self, image_id, attribute, operation, users, groups):
self.images.expireCache()
Threads.instance().runThread(self.__modify_image_attribute_cb__,
({'image_id':image_id, 'attribute':attribute,
'operation':operation, 'users':users, 'groups':groups}, callback))
def __modify_image_attribute_cb__(self, kwargs, callback):
try:
ret = self.clc.modify_image_attribute(kwargs['image_id'], kwargs['attribute'], kwargs['operation'], kwargs['users'], kwargs['groups'])
Threads.instance().invokeCallback(callback, Response(data=ret))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
# returns True if successful
def reset_image_attribute(self, image_id, attribute):
self.images.expireCache()
Threads.instance().runThread(self.__reset_image_attribute_cb__,
({'image_id':image_id, 'attribute':attribute}, callback))
def __reset_image_attribute_cb__(self, kwargs, callback):
try:
ret = self.clc.reset_image_attribute(kwargs['image_id'], kwargs['attribute'])
Threads.instance().invokeCallback(callback, Response(data=ret))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def get_all_instances(self, callback):
if self.instances.isCacheStale():
Threads.instance().runThread(self.__get_all_instances_cb__, ({}, callback))
else:
callback(Response(data=self.__normalize_instances__(self.instances.values)))
def __get_all_instances_cb__(self, kwargs, callback):
示例2: CachingScaleInterface
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import expireCache [as 别名]
class CachingScaleInterface(ScaleInterface):
scaling = None
# load saved state to simulate Walrus
def __init__(self, scaleinterface, config):
self.scaling = scaleinterface
pollfreq = config.getint('server', 'pollfreq')
try:
freq = config.getint('server', 'pollfreq.scalinggroups')
except ConfigParser.NoOptionError:
freq = pollfreq
self.groups = Cache(freq)
try:
freq = config.getint('server', 'pollfreq.scalinginstances')
except ConfigParser.NoOptionError:
freq = pollfreq
self.instances = Cache(freq)
try:
freq = config.getint('server', 'pollfreq.launchconfigs')
except ConfigParser.NoOptionError:
freq = pollfreq
self.launchconfigs = Cache(freq)
##
# autoscaling methods
##
def create_auto_scaling_group(self, as_group, callback=None):
self.groups.expireCache()
params = {'as_group':as_group}
Threads.instance().runThread(self.__create_auto_scaling_group_cb__, (params, callback))
def __create_auto_scaling_group_cb__(self, kwargs, callback):
try:
ret = self.scaling.create_auto_scaling_group(kwargs['as_group'])
Threads.instance().invokeCallback(callback, Response(data=ret))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def delete_auto_scaling_group(self, name, force_delete=False, callback=None):
self.groups.expireCache()
params = {'name':name, 'force_delete':force_delete}
Threads.instance().runThread(self.__delete_auto_scaling_group_cb__, (params, callback))
def __delete_auto_scaling_group_cb__(self, kwargs, callback):
try:
ret = self.scaling.delete_auto_scaling_group(kwargs['name'], kwargs['force_delete'])
Threads.instance().invokeCallback(callback, Response(data=ret))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def get_all_groups(self, names=None, max_records=None, next_token=None, callback=None):
params = {'names':names, 'max_records':max_records, 'next_token':next_token}
Threads.instance().runThread(self.__get_all_groups_cb__, (params, callback))
def __get_all_groups_cb__(self, kwargs, callback):
try:
self.groups.values = self.scaling.get_all_groups(kwargs['names'],
kwargs['max_records'], kwargs['next_token'])
Threads.instance().invokeCallback(callback, Response(data=self.groups.values))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def get_all_autoscaling_instances(self, instance_ids=None, max_records=None, next_token=None, callback=None):
params = {'instance_ids':instance_ids, 'max_records':max_records,
'next_token':next_token}
Threads.instance().runThread(self.__get_all_autoscaling_instances_cb__,
(params, callback))
def __get_all_autoscaling_instances_cb__(self, kwargs, callback):
try:
self.instances.values = self.scaling.get_all_autoscaling_instances(
kwargs['instance_ids'],
kwargs['max_records'], kwargs['next_token'])
Threads.instance().invokeCallback(callback, Response(data=self.instances.values))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def set_desired_capacity(self, group_name, desired_capacity, honor_cooldown=False, callback=None):
self.groups.expireCache()
params = {'group_name':group_name, 'desired_capacity':desired_capacity,
'honor_cooldown':honor_cooldown}
Threads.instance().runThread(self.__set_desired_capacity_cb__, (params, callback))
def __set_desired_capacity_cb__(self, kwargs, callback):
try:
ret = self.scaling.set_desired_capacity(kwargs['group_name'],
kwargs['desired_capacity'], kwargs['honor_cooldown'])
Threads.instance().invokeCallback(callback, Response(data=ret))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def set_instance_health(self, instance_id, health_status, should_respect_grace_period=True):
params = {'instance_id':instance_id, 'health_status':health_status,
'should_respect_grace_period':should_respect_grace_period}
Threads.instance().runThread(self.__set_instance_health_cb__, (params, callback))
def __set_instance_health_cb__(self, kwargs, callback):
try:
ret = self.scaling.set_instance_health(kwargs['instance_id'],
kwargs['health_status'], kwargs['should_respect_grace_period'])
#.........这里部分代码省略.........
示例3: CachingBalanceInterface
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import expireCache [as 别名]
class CachingBalanceInterface(BalanceInterface):
bal = None
# load saved state to simulate Walrus
def __init__(self, balanceinterface, config):
self.bal = balanceinterface
pollfreq = config.getint('server', 'pollfreq')
try:
freq = config.getint('server', 'pollfreq.balancers')
except ConfigParser.NoOptionError:
freq = pollfreq
self.balancers = Cache(freq)
try:
freq = config.getint('server', 'pollfreq.elb_instances')
except ConfigParser.NoOptionError:
freq = pollfreq
self.instances = Cache(freq)
##
# elb methods
##
def create_load_balancer(self, name, zones, listeners, subnets=None,
security_groups=None, scheme='internet-facing', callback=None):
self.balancers.expireCache()
params = {'name':name, 'zones':zones, 'listeners':listeners, 'subnets':subnets,
'security_groups':security_groups, 'scheme':scheme}
Threads.instance().runThread(self.__create_load_balancer_cb__, (params, callback))
def __create_load_balancer_cb__(self, kwargs, callback):
try:
ret = self.bal.create_load_balancer(kwargs['name'], kwargs['zones'], kwargs['listeners'],
kwargs['subnets'], kwargs['security_groups'], kwargs['scheme'])
Threads.instance().invokeCallback(callback, Response(data=ret))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def delete_load_balancer(self, name, callback=None):
self.balancers.expireCache()
params = {'name':name}
Threads.instance().runThread(self.__delete_load_balancer_cb__, (params, callback))
def __delete_load_balancer_cb__(self, kwargs, callback):
try:
ret = self.bal.delete_load_balancer(kwargs['name'])
Threads.instance().invokeCallback(callback, Response(data=ret))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def get_all_load_balancers(self, load_balancer_names=None, callback=None):
if self.balancers.isCacheStale():
params = {'load_balancer_names':load_balancer_names}
Threads.instance().runThread(self.__get_all_load_balancers_cb__, (params, callback))
else:
callback(Response(data=self.balancers.values))
def __get_all_load_balancers_cb__(self, kwargs, callback):
try:
self.balancers.values = self.bal.get_all_load_balancers(kwargs['load_balancer_names'])
Threads.instance().invokeCallback(callback, Response(data=self.balancers.values))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def deregister_instances(self, load_balancer_name, instances, callback=None):
params = {'load_balancer_name':load_balancer_name, 'instances':instances}
Threads.instance().runThread(self.__deregister_instances_cb__, (params, callback))
def __deregister_instances_cb__(self, kwargs, callback):
try:
ret = self.bal.deregister_instances(kwargs['load_balancer_name'], kwargs['instances'])
Threads.instance().invokeCallback(callback, Response(data=ret))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def register_instances(self, load_balancer_name, instances, callback=None):
params = {'load_balancer_name':load_balancer_name, 'instances':instances}
Threads.instance().runThread(self.__register_instances_cb__, (params, callback))
def __register_instances_cb__(self, kwargs, callback):
try:
ret = self.bal.register_instances(kwargs['load_balancer_name'], kwargs['instances'])
Threads.instance().invokeCallback(callback, Response(data=ret))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def create_load_balancer_listeners(self, name, listeners, callback=None):
params = {'name':name, 'listeners':listeners}
Threads.instance().runThread(self.__create_load_balancer_listeners_cb__, (params, callback))
def __create_load_balancer_listeners_cb__(self, kwargs, callback):
try:
ret = self.bal.create_load_balancer_listeners(kwargs['name'], kwargs['listeners'])
Threads.instance().invokeCallback(callback, Response(data=ret))
except Exception as ex:
Threads.instance().invokeCallback(callback, Response(error=ex))
def delete_load_balancer_listeners(self, name, ports, callback=None):
params = {'name':name, 'ports':ports}
Threads.instance().runThread(self.__delete_load_balancer_listeners_cb__, (params, callback))
def __delete_load_balancer_listeners_cb__(self, kwargs, callback):
#.........这里部分代码省略.........