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


Python cachetools.LRUCache方法代码示例

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


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

示例1: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def __init__(
        self, env, slave_server: SlaveServer, port, host, methods: AsyncMethods
    ):
        self.loop = asyncio.get_event_loop()
        self.port = port
        self.host = host
        self.env = env
        self.slave = slave_server
        self.counters = dict()
        self.pending_tx_cache = LRUCache(maxsize=1024)

        # Bind RPC handler functions to this instance
        self.handlers = AsyncMethods()
        for rpc_name in methods:
            func = methods[rpc_name]
            self.handlers[rpc_name] = func.__get__(self, self.__class__)

        self.shard_subscription_managers = self.slave.shard_subscription_managers 
开发者ID:QuarkChain,项目名称:pyquarkchain,代码行数:20,代码来源:jsonrpc.py

示例2: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def __init__(self, session: aiohttp.ClientSession,
                 app_name: str, app_key: str, app_id: str,
                 client_id: str, client_secret: str) -> None:
        #: Name of app
        self.name = app_name
        #: ID of app
        self.app_id = app_id
        #: Authorization key
        self.app_key = app_key
        #: OAUTH client ID
        self.client_id = client_id
        #: OAUTH client secret
        self.client_secret = client_secret
        #: Cache for API queries
        self._cache = cachetools.LRUCache(maxsize=500)
        #: Our client session
        self._session = session
        #: JWT and its expiry
        self._jwt: Tuple[int, str] = (0, "")
        #: OAUTH tokens for installations
        self._tokens: Dict[str, Tuple[int, str]] = {}
        #: GitHubHandlers for each installation
        self._handlers: Dict[Tuple[str, str], GitHubHandler] = {}
        #: GitHubHandlers for each user token->time,handler
        self._user_handlers: Dict[str, Tuple[int, GitHubHandler]] = {} 
开发者ID:bioconda,项目名称:bioconda-utils,代码行数:27,代码来源:githubhandler.py

示例3: __init__

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

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

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

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

示例4: load_media

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def load_media(self, server, mxc_server=None, mxc_path=None):
        server, _ = Servers.get_or_create(name=server)

        if not mxc_path:
            media_cache = LRUCache(maxsize=MAX_LOADED_MEDIA)

            for i, m in enumerate(server.media):
                if i > MAX_LOADED_MEDIA:
                    break

                media = MediaInfo(m.mxc_server, m.mxc_path, m.key, m.iv, m.hashes)
                media_cache[(m.mxc_server, m.mxc_path)] = media

            return media_cache
        else:
            m = PanMediaInfo.get_or_none(
                PanMediaInfo.server == server,
                PanMediaInfo.mxc_server == mxc_server,
                PanMediaInfo.mxc_path == mxc_path,
            )

            if not m:
                return None

            return MediaInfo(m.mxc_server, m.mxc_path, m.key, m.iv, m.hashes) 
开发者ID:matrix-org,项目名称:pantalaimon,代码行数:27,代码来源:store.py

示例5: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def __init__(self, device=None):
    """Creates a new instance of an eager executor.

    Args:
      device: An optional `tf.config.LogicalDevice` that this executor will
        schedule all of its operations to run on. For example, the list of
        logical devices can be obtained using
        `tf.config.list_logical_devices()`.

    Raises:
      RuntimeError: If not executing eagerly.
      TypeError: If the device is not a `tf.config.LogicalDevice`.
      ValueError: If there is no device `device`.
    """
    if not tf.executing_eagerly():
      raise RuntimeError('The eager executor may only be used in eager mode.')
    if device is not None:
      py_typecheck.check_type(device, tf.config.LogicalDevice)
      self._device = device
    else:
      self._device = None
    self._tf_function_cache = cachetools.LRUCache(_TF_FUNCTION_CACHE_SIZE) 
开发者ID:tensorflow,项目名称:federated,代码行数:24,代码来源:eager_tf_executor.py

示例6: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def __init__(self, target_executor, cache=None):
    """Creates a new instance of this executor.

    Args:
      target_executor: An instance of `executor_base.Executor`.
      cache: The cache to use (must be an instance of `cachetools.Cache`). If
        unspecified, by default we construct a 1000-element LRU cache.
    """
    py_typecheck.check_type(target_executor, executor_base.Executor)
    if cache is not None:
      py_typecheck.check_type(cache, cachetools.Cache)
    else:
      cache = cachetools.LRUCache(_DEFAULT_CACHE_SIZE)
    self._target_executor = target_executor
    self._cache = cache
    self._num_values_created = 0 
开发者ID:tensorflow,项目名称:federated,代码行数:18,代码来源:caching_executor.py

示例7: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def __init__(self, filename: str, tree_conf: TreeConf,
                 cache_size: int=512):
        self._filename = filename
        self._tree_conf = tree_conf
        self._lock = rwlock.RWLock()

        if cache_size == 0:
            self._cache = FakeCache()
        else:
            self._cache = cachetools.LRUCache(maxsize=cache_size)

        self._fd, self._dir_fd = open_file_in_dir(filename)

        self._wal = WAL(filename, tree_conf.page_size)
        if self._wal.needs_recovery:
            self.perform_checkpoint(reopen_wal=True)

        # Get the next available page
        self._fd.seek(0, io.SEEK_END)
        last_byte = self._fd.tell()
        self.last_page = int(last_byte / self._tree_conf.page_size)
        self._freelist_start_page = 0

        # Todo: Remove this, it should only be in Tree
        self._root_node_page = 0 
开发者ID:NicolasLM,项目名称:bplustree,代码行数:27,代码来源:memory.py

示例8: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def __init__(self, conf):
        super(DirBackend, self).__init__(conf)
        max_cache_size = self._conf.get('max_cache_size')
        if max_cache_size is not None:
            max_cache_size = int(max_cache_size)
            if max_cache_size < 1:
                raise ValueError("Maximum cache size must be greater than"
                                 " or equal to one")
            self.file_cache = cachetools.LRUCache(max_cache_size)
        else:
            self.file_cache = {}
        self.encoding = self._conf.get('encoding', self.DEFAULT_FILE_ENCODING)
        if not self._path:
            raise ValueError("Empty path is disallowed")
        self._path = os.path.abspath(self._path)
        self.lock = fasteners.ReaderWriterLock() 
开发者ID:openstack,项目名称:taskflow,代码行数:18,代码来源:impl_dir.py

示例9: test_lru

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def test_lru(self):
        cache = LRUCache(maxsize=2)

        cache[1] = 1
        cache[2] = 2
        cache[3] = 3

        self.assertEqual(len(cache), 2)
        self.assertEqual(cache[2], 2)
        self.assertEqual(cache[3], 3)
        self.assertNotIn(1, cache)

        cache[2]
        cache[4] = 4
        self.assertEqual(len(cache), 2)
        self.assertEqual(cache[2], 2)
        self.assertEqual(cache[4], 4)
        self.assertNotIn(3, cache)

        cache[5] = 5
        self.assertEqual(len(cache), 2)
        self.assertEqual(cache[4], 4)
        self.assertEqual(cache[5], 5)
        self.assertNotIn(2, cache) 
开发者ID:tkem,项目名称:cachetools,代码行数:26,代码来源:test_lru.py

示例10: test_lru_getsizeof

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def test_lru_getsizeof(self):
        cache = LRUCache(maxsize=3, getsizeof=lambda x: x)

        cache[1] = 1
        cache[2] = 2

        self.assertEqual(len(cache), 2)
        self.assertEqual(cache[1], 1)
        self.assertEqual(cache[2], 2)

        cache[3] = 3

        self.assertEqual(len(cache), 1)
        self.assertEqual(cache[3], 3)
        self.assertNotIn(1, cache)
        self.assertNotIn(2, cache)

        with self.assertRaises(ValueError):
            cache[4] = 4
        self.assertEqual(len(cache), 1)
        self.assertEqual(cache[3], 3) 
开发者ID:tkem,项目名称:cachetools,代码行数:23,代码来源:test_lru.py

示例11: get_cache

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def get_cache(maxsize=10000):
    """
    Get an instance of cachetools.cache

    Parameters
    ----------
    maxsize: int
        The max size for the cache (``10000``, by default)

    Returns
    -------
    cachetools.cache
        An instance of cachetools.cache

    """
    global cache
    if cache is None:
        cache = LRUCache(maxsize)
    return cache 
开发者ID:NCATS-Tangerine,项目名称:kgx,代码行数:21,代码来源:kgx_utils.py

示例12: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def __init__(self, config, with_cache=False):
        """
        Initialize Mapchete processing endpoint.

        Parameters
        ----------
        config : MapcheteConfig
            Mapchete process configuration
        with_cache : bool
            cache processed output data in memory (default: False)
        """
        logger.info("initialize process")
        if not isinstance(config, MapcheteConfig):
            raise TypeError("config must be MapcheteConfig object")
        self.config = config
        self.process_name = self.config.process_name
        self.with_cache = True if self.config.mode == "memory" else with_cache
        if self.with_cache:
            self.process_tile_cache = LRUCache(maxsize=512)
            self.current_processes = {}
            self.process_lock = threading.Lock()
        self._count_tiles_cache = {} 
开发者ID:ungarj,项目名称:mapchete,代码行数:24,代码来源:_core.py

示例13: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def __init__(self):
        self._cache = LRUCache(maxsize=4096)
        self._lock = Lock() 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:5,代码来源:gossip_handlers.py

示例14: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def __init__(self, check_blocks: int, percentile: int):
        self.cache = LRUCache(maxsize=128)
        self.check_blocks = check_blocks
        self.percentile = percentile 
开发者ID:QuarkChain,项目名称:pyquarkchain,代码行数:6,代码来源:shard_state.py

示例15: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import LRUCache [as 别名]
def __init__(self, db, env, branch: Branch):
        self.env = env
        self.db = db
        self.branch = branch

        # height -> set(minor block hash) for counting wasted blocks
        self.height_to_minor_block_hashes = dict()
        self.rblock_cache = LRUCache(maxsize=256)
        self.mblock_cache = LRUCache(maxsize=4096)
        self.mblock_header_cache = LRUCache(maxsize=10240)

    # ------------------------- Root block db operations -------------------------------- 
开发者ID:QuarkChain,项目名称:pyquarkchain,代码行数:14,代码来源:shard_db_operator.py


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