當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。