当前位置: 首页>>代码示例>>Python>>正文


Python cachetools.TTLCache方法代码示例

本文整理汇总了Python中cachetools.TTLCache方法的典型用法代码示例。如果您正苦于以下问题:Python cachetools.TTLCache方法的具体用法?Python cachetools.TTLCache怎么用?Python cachetools.TTLCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cachetools的用法示例。


在下文中一共展示了cachetools.TTLCache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def __init__(self, msg_queue, db_interface):
		self.response_queue = msg_queue
		self.log = logging.getLogger("Main.LinkAggregator")

		try:
			signal.signal(signal.SIGINT, signal.SIG_IGN)
		except ValueError:
			self.log.warning("Cannot configure job fetcher task to ignore SIGINT. May be an issue.")

		# LRU Cache with a maxsize of 1 million, and a TTL of 6 hours
		self.seen = cachetools.TTLCache(maxsize=1000 * 1000, ttl=60 * 60 * 6)

		self.queue_items = 0
		self.link_count = 0
		self.amqpUpdateCount = 0
		self.deathCounter = 0

		self.batched_links = []
		self.pending_upserts = []

		self.db_int = db_interface
		self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=6)

		self.check_init_func() 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:26,代码来源:UrlUpserter.py

示例2: get_feed_article_meta

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def get_feed_article_meta(feedid):
	global QIDIAN_META_CACHE
	if feedid in QIDIAN_META_CACHE:
		return QIDIAN_META_CACHE[feedid]

	sess = get_db_session(flask_sess_if_possible=False)
	have = sess.query(QidianFeedPostMeta).filter(QidianFeedPostMeta.contentid == feedid).scalar()
	if have:
		ret = have.meta
	else:
		ret = {}

	sess.commit()

	try:
		QIDIAN_META_CACHE[feedid] = ret
	except KeyError:
		QIDIAN_META_CACHE = cachetools.TTLCache(maxsize=5000, ttl=60 * 5)
		QIDIAN_META_CACHE[feedid] = ret


	return ret 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:24,代码来源:rss_func_db.py

示例3: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def __init__(self, maxsize, ttl, out_deque=None, **kw):
        """Constructor.

        Args:
          maxsize (int): the maximum number of entries in the queue
          ttl (int): the ttl for entries added to the cache
          out_deque :class:`collections.deque`: a `deque` in which to add items
            that expire from the cache
          **kw: the other keyword args supported by the constructor to
            :class:`cachetools.TTLCache`

        Raises:
          ValueError: if out_deque is not a collections.deque

        """
        super(DequeOutTTLCache, self).__init__(maxsize, ttl, **kw)
        if out_deque is None:
            out_deque = collections.deque()
        elif not isinstance(out_deque, collections.deque):
            raise ValueError(u'out_deque should be a collections.deque')
        self._out_deque = out_deque
        self._tracking = {} 
开发者ID:cloudendpoints,项目名称:endpoints-management-python,代码行数:24,代码来源:caches.py

示例4: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def __init__(self, token, session=None, timeout=30, is_async=False, **options):
        # Async options
        self.is_async = is_async
        self.loop = options.get('loop', asyncio.get_event_loop()) if self.is_async else None
        self.connector = options.get('connector')

        # Session and request options
        self.session = options.get('session') or (
            aiohttp.ClientSession(loop=self.loop, connector=self.connector) if self.is_async else requests.Session()
        )
        self.timeout = timeout
        self.prevent_ratelimit = options.get('prevent_ratelimit', False)
        self.api = API(options.get('base_url'), version=1)

        self.debug = options.get('debug', False)
        self.cache = TTLCache(3200 * 3, 60 * 3)  # 3200 requests per minute

        # Request/response headers
        self.headers = {
            'Authorization': 'Bearer {}'.format(token),
            'User-Agent': 'brawlstats/{0} (Python {1[0]}.{1[1]})'.format(self.api.VERSION, sys.version_info),
            'Accept-Encoding': 'gzip'
        } 
开发者ID:SharpBit,项目名称:brawlstats,代码行数:25,代码来源:core.py

示例5: async_ttl_cache

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def async_ttl_cache(ttl: int = 3600, maxsize: int = 1):
    cache = cachetools.TTLCache(ttl=ttl, maxsize=maxsize)

    def decorator(fn):
        @functools.wraps(fn)
        async def memoize(*args, **kwargs):
            key = str((args, kwargs))
            try:
                cache[key] = cache.pop(key)
            except KeyError:
                cache[key] = await fn(*args, **kwargs)
            return cache[key]
        return memoize

    return decorator 
开发者ID:CoinAlpha,项目名称:hummingbot,代码行数:17,代码来源:__init__.py

示例6: __init_pool

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def __init_pool(self, pool_name):
		self.worker_pools[pool_name] = {
			'outgoing_q'   : queue.Queue(),
			'incoming_q'   : queue.Queue(),
			'workers'      : [],

			'dispatch_map' : cachetools.TTLCache(maxsize=10000, ttl=hours(24)),

			# The chunk structure is slightly annoying, so just limit to 50 partial message keys, and
			# a TTL of 3 hours.
			# 'chunk_cache'  : fdict.sfdict(filename=os.path.join(settings_file.CHUNK_CACHE_DIR, "chunk_cache_{}.db".format(pool_name.lower()))),
			'chunk_cache'   : cachetools.TTLCache(maxsize=50, ttl=hours(3)),
			'chunk_lock'   : threading.Lock(),
		} 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:16,代码来源:MessageProcessor.py

示例7: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def __init__(self):
        ttl = 60 * 5
        max_size = 500
        self._cache = TTLCache(max_size, ttl) 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:6,代码来源:hash_request_cache.py

示例8: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def __init__(self, opts):
        super(CustomThreatService, self).__init__(**_make_args(opts))

        # Configurable options
        self.options = opts.get(CONFIG_SECTION, {})

        # Do we support "file-content" artifacts?  Default is no.
        # TODO add implementation support to parse the file content
        self.support_upload_file = bool(self.options.get(CONFIG_UPLOAD_FILE.key, CONFIG_UPLOAD_FILE.default))

        # Default time that this service will tell Resilient to retry
        self.first_retry_secs = int(self.options.get(CONFIG_FIRST_RETRY_SECS.key, CONFIG_FIRST_RETRY_SECS.default)) or 5
        self.later_retry_secs = int(self.options.get(CONFIG_LATER_RETRY_SECS.key, CONFIG_LATER_RETRY_SECS.default)) or 60

        # Size of the request cache
        self.cache_size = int(self.options.get(CONFIG_CACHE_SIZE.key, CONFIG_CACHE_SIZE.default))
        # TTL of the request cache (millis before we give up on a request lookup)
        self.cache_ttl = int(self.options.get(CONFIG_CACHE_TTL.key, CONFIG_CACHE_TTL.default))

        # Limit to the number of queries we'll answer for unfinished searchers (count before giving up on them)
        self.max_retries = int(self.options.get(CONFIG_MAX_RETRIES.key, CONFIG_MAX_RETRIES.default))

        # IDs and their results are maintained in a cache so that we can set
        # an upper bound on the number of in-progress and recent lookups.
        self.cache = TTLCache(maxsize=self.cache_size, ttl=self.cache_ttl)

        # Helper component does event dispatch work
        self.async_helper = CustomThreatServiceHelper(self)
        (self.helper_thread, self.bridge) = self.async_helper.start()

        urls = ["{0}/{1}".format(self.channel, e) for e in self.events()]
        LOG.info("Web handler for %s", ", ".join(urls))

    # Web endpoints 
开发者ID:ibmresilient,项目名称:resilient-python-api,代码行数:36,代码来源:threat_webservice.py

示例9: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def __init__(self):
        self.paginators = cachetools.TTLCache(500, 300) 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:4,代码来源:paginator.py

示例10: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def __init__(self, cfg):
        """
        :type cfg: sigma.core.mechanics.config.CacheConfig
        :param cfg: The CacheConfig object for getting the configuration parameters.
        """
        super().__init__(cfg)
        self.cache = cachetools.TTLCache(self.cfg.size, self.cfg.time) 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:9,代码来源:caching.py

示例11: init

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def init(cls, conf):
        cls.config = conf
        cls.zil_conf = conf["zilliqa"]
        cls.api = zilliqa_api.API(cls.zil_conf["api_endpoint"])
        cls.cache = TTLCache(maxsize=64, ttl=cls.zil_conf["update_interval"]) 
开发者ID:DurianStallSingapore,项目名称:Zilliqa-Mining-Proxy,代码行数:7,代码来源:blockchain.py

示例12: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def __init__(self, **cache_options):
        self.cache = cachetools.TTLCache(**cache_options) 
开发者ID:ipinfo,项目名称:python,代码行数:4,代码来源:default.py

示例13: _cached

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def _cached(fn):
    _fn_cache_lock = threading.Lock()
    # short-term cache to avoid retrieving the same data several times in succession
    cache = cachetools.TTLCache(1024, 30) if os.environ.get('GSQ_SEC_MASTER_CACHE') else None

    @wraps(fn)
    def wrapper(*args, **kwargs):
        if cache is not None:
            args = [tuple(x) if isinstance(x, list) else x for x in args]  # tuples are hashable
            k = cachetools.keys.hashkey(GsSession.current, *args, **kwargs)
            with metalock:
                invocation_lock = invocation_locks.setdefault(f'{fn.__name__}:{k}', threading.Lock())
            with invocation_lock:
                with _fn_cache_lock:
                    result = cache.get(k)
                if result:
                    _logger.debug('%s cache hit: %s, %s', fn.__name__, str(args), str(kwargs))
                    return result
                result = fn(*args, **kwargs)
                with _fn_cache_lock:
                    cache[k] = result
        else:
            result = fn(*args, **kwargs)
        return result

    return wrapper 
开发者ID:goldmansachs,项目名称:gs-quant,代码行数:28,代码来源:assets.py

示例14: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def __init__(self, hook=None, bot_token=None):
        self.hook = hook
        self.bot_token = bot_token

        self.cache = TTLCache(maxsize=128, ttl=60*30) 
开发者ID:openai,项目名称:kubernetes-ec2-autoscaler,代码行数:7,代码来源:notification.py

示例15: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import TTLCache [as 别名]
def __init__(self, size, ttl):
        """Initialize the memory cache."""
        super(MemoryCache, self).__init__()
        self.__size = size
        self.__ttl = ttl
        self.__cache = cachetools.TTLCache(maxsize=self.__size, ttl=self.__ttl) 
开发者ID:criteo,项目名称:biggraphite,代码行数:8,代码来源:accessor_cache.py


注:本文中的cachetools.TTLCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。