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


Python pylru.lrucache函数代码示例

本文整理汇总了Python中pylru.lrucache函数的典型用法代码示例。如果您正苦于以下问题:Python lrucache函数的具体用法?Python lrucache怎么用?Python lrucache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: setup_nodes

def setup_nodes(g):
    for cdn in cdns:
        g.node[cdn]["storage"] = CDNStorage()
        g.node[cdn]["color"] = "#ff0000"
        g.node[cdn]["capacity"] = cdn_capacity
        g.node[cdn]["size"] = 50
        g.node[cdn]["type"] = "CDN"

    for vcdn_node in vcdns:
        g.node[vcdn_node]["storage"] = pylru.lrucache(vcdn_cache_size)
        #g.node[vcdn_node]["storage"] = CDNStorage()
        g.node[vcdn_node]["capacity"] = vcdn_capacity
        g.node[vcdn_node]["type"] = "VCDN"
        g.node[vcdn_node]["color"] = "#00ff00"
        g.node[vcdn_node]["size"] = 20

    for mucdn_node in mucdns:
        g.node[mucdn_node]["storage"] = pylru.lrucache(mucdn_cache_size)
        #g.node[mucdn_node]["storage"] = CDNStorage()
        g.node[mucdn_node]["capacity"] = mucdn_capacity
        g.node[mucdn_node]["size"] = 10
        g.node[mucdn_node]["type"] = "MUCDN"
        g.node[mucdn_node]["color"] = "#aaaaff"

    for consumer in consumers:
        g.node[consumer]["color"] = "#000000"
        g.node[consumer]["size"] = 5
        g.node[mucdn_node]["type"] = "CONSUMER"
开发者ID:dngroup,项目名称:simuservice,代码行数:28,代码来源:discrete_simu.py

示例2: __init__

 def __init__(self, left, right, target, max_size=128):
     super().__init__()
     self.__cache_left = pylru.lrucache(size=max_size)
     self.__cache_right = pylru.lrucache(size=max_size)
     self.__left = left
     self.__right = right
     self.__target = target
     self.__max_size = max_size
开发者ID:conley,项目名称:babygogo,代码行数:8,代码来源:stream.py

示例3: LoadCacheFromFile

def LoadCacheFromFile(filename):
  """
  This function returns a pylru.lrucache object containing (key, value) pairs.
  The keys are strings containing the URLs of submissions. The values are just
  dummy values to be ignored. We try to read the file whose name is given as an
  argument. If we can, we return a pylru.lrucache object containing its
  contents, with the top line of the file being the most recently used entry
  and the last line of the file being the least recently used entry. If we
  cannot read the file, we return an empty pylru.lrucache object. This function
  should return a cache containing the same state as the cache last passed to
  StoreCacheToFile().
  """
  cache = pylru.lrucache(MAX_SUBMISSIONS)

  try:
    f = open(filename)
    contents = f.readlines()
    f.close()
  except:  # Can't read the file; give up and start from scratch.
    print "WARNING: Unable to load cache. Starting over with an empty cache."
    return cache

  # The most recently used line is first in the file, which means it should be
  # inserted into the cache last.
  for line in reversed(contents):
    cache[line.strip()] = True  # Dummy value
  return cache
开发者ID:penguinland,项目名称:expired_link_bot,代码行数:27,代码来源:expired_link_bot.py

示例4: __init__

    def __init__(self, available_registers, spill_memory_base_label, spill_memory_size, word_size=4):
        """ The constructor.

        Creates a RegisterUseTable with it's allowed set of registers and available spill memory. Arbitrarily sized
        words are allowed, but (sensible) 4 byte words are used by default.

        :param available_registers: A sequence (preferably set or tuple) of the registers the table is allowed to use
                                    without reservation.
        :spill_memory_base_label: The MIPS label where the spill memory is located.
        :param spill_memory_size: The amount of spill memory available in bytes.
        :word_size: The size of a word (register capacity) in bytes.
        :return: A constructed RegisterUseTable object.
        """

        self.spill_mem_base_label = spill_memory_base_label
        self.spill_mem_size = spill_memory_size

        self.available_registers = list(reversed(available_registers))
        self.available_spill_memory_words = list(reversed(range(0, spill_memory_size, word_size)))

        self.lru_cache = pylru.lrucache(size=len(available_registers), callback=self._spill)
        self.spilled_registers = {}

        self._spill_code = []
        self._freed_physical_register = None
开发者ID:T-R0D,项目名称:Past-Courses,代码行数:25,代码来源:register_management.py

示例5: register_cache

    def register_cache(cls, key, size=512):
        """Create a new cache for this entity, keyed by attribute.

        Currently these caches are not searched, they merely serve as another
        reference to keep their entries in _instances alive.

        There is support for caching UIDs and Attribute values when
        they change, if you want to register anything else (such as bare
        properties not tied to an Attribute) then you'll need to make sure to
        update the cache yourself when their values change.

        :param str key: The attribute name to use as a key
        :param int size: The size of the cache to create
        :returns None:
        :raises KeyError: If a cache already exists for `key`

        """
        if key in cls._caches:
            raise AlreadyExists(key, cls._caches[key])
        cache = lrucache(size, cls._cache_eject_callback)
        cls._caches[key] = cache
        # Fill the cache with any existing entity data.
        for entity in cls._instances.values():
            attr_value = getattr(entity, key)
            if attr_value not in (None, Unset):
                if attr_value not in cache:
                    cache[attr_value] = {entity}
                else:
                    cache[attr_value].add(entity)
开发者ID:whutch,项目名称:cwmud,代码行数:29,代码来源:entities.py

示例6: load_cache

 def load_cache(self):
     '''Create a pylru.lrucache object prepopulated with saved data.'''
     cache = pylru.lrucache(self.size)
     # There should be a more efficient way to do this, by hooking into
     # the json module directly.
     self._populate_cache_from_file(self.filename, cache)
     return cache
开发者ID:petefoth,项目名称:morph,代码行数:7,代码来源:sourceresolver.py

示例7: __init__

 def __init__(self,file_cache_count = 200,threshold=1000,buckets=60):
     self.file_cache = pylru.lrucache(file_cache_count)
     self.buckets = buckets
     self.threshold = threshold
     self.event_index = 0
     self.event_counts = {}
     self.event_total = 0
开发者ID:sile16,项目名称:isilon-audit,代码行数:7,代码来源:cepa.py

示例8: __init__

	def __init__(self, basefolder, create=False):
		"""
		Initializes a ``LocalFileStorage`` instance under the given ``basefolder``, creating the necessary folder
		if necessary and ``create`` is set to ``True``.

		:param string basefolder: the path to the folder under which to create the storage
		:param bool create:       ``True`` if the folder should be created if it doesn't exist yet, ``False`` otherwise
		"""
		self._logger = logging.getLogger(__name__)

		self.basefolder = os.path.realpath(os.path.abspath(basefolder))
		if not os.path.exists(self.basefolder) and create:
			os.makedirs(self.basefolder)
		if not os.path.exists(self.basefolder) or not os.path.isdir(self.basefolder):
			raise RuntimeError("{basefolder} is not a valid directory".format(**locals()))

		import threading
		self._metadata_lock = threading.Lock()

		self._metadata_cache = pylru.lrucache(10)

		from slugify import Slugify
		self._slugify = Slugify()
		self._slugify.safe_chars = "-_.() "

		self._old_metadata = None
		self._initialize_metadata()
开发者ID:leductan-nguyen,项目名称:RaionPi,代码行数:27,代码来源:storage.py

示例9: __init__

 def __init__(self, size=10):
     """
     :param size: int, size of the cache, should match the actual concurrent users,
                 as we should only assign one key-value for one user
     :return:
     """
     self.cache = pylru.lrucache(size)
     self.size = size
开发者ID:manyan,项目名称:pythonlrucache,代码行数:8,代码来源:cache.py

示例10: lrucache

def lrucache(size):
    try:
        #raise ImportError("no pylru")
        import pylru
        return pylru.lrucache(size)
    except ImportError:
        warnings.warn("pylru not available; using simple cache with no size limit")
        return {}
开发者ID:reflectometry,项目名称:reduction,代码行数:8,代码来源:fakeredis.py

示例11: __init__

  def __init__(self, options):
    """Initializes an LruBackend.

    Args:
      options: a dictionary that contains configuration options.
    """
    capacity = options["capacity"] if "capacity" in options else 200
    self._cache = pylru.lrucache(capacity)
开发者ID:catapult-project,项目名称:catapult,代码行数:8,代码来源:caches.py

示例12: __init__

    def __init__(self, size=1024):
        try:
            import pylru
        except ImportError:
            raise ImportError("Could not find pylru.  This packages is " +
                              "required when using ores.score_caches.LRU.")

        self.lru = pylru.lrucache(size)
开发者ID:wikimedia,项目名称:mediawiki-services-ores,代码行数:8,代码来源:lru.py

示例13: __init__

 def __init__(self, index_dir):
     self.index_dir = index_dir
     self.catalog_map = None
     self.doc_id_map = None
     self.id_doc_map = dict()
     self.dlen_map = None
     self.token_id_map = None
     self.index_file = None
     self.mem_cache = pylru.lrucache(10000)
     self.load_meta()
开发者ID:heroxdream,项目名称:information-retrieval,代码行数:10,代码来源:IndexManager.py

示例14: __init__

    def __init__(self, name, maxSize = 1000000):

        self._store = pylru.lrucache(maxSize)
        self._name = name
        self._start = time.time()
        self._numWrites = 0
        self._numReads = 0
        self._numHits = 0
        self._numMisses = 0
        self.getStats()
开发者ID:EverythingMe,项目名称:snakepit,代码行数:10,代码来源:__init__.py

示例15: pmemoize

def pmemoize(obj):
    cache = obj.cache = pylru.lrucache(500)

    @functools.wraps(obj)
    def memoizer(*args, **kwargs):
        key = marshal.dumps([args, kwargs])
        if key not in cache:
            cache[key] = obj(*args, **kwargs)
        return cache[key]
    return memoizer
开发者ID:RuleWorld,项目名称:atomizer,代码行数:10,代码来源:util.py


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