# HG changeset patch # User Jun Wu <qu...@fb.com> # Date 1488947963 28800 # Tue Mar 07 20:39:23 2017 -0800 # Node ID 60eb2c2b5196a62d635dbe0eb1e29fdd945d5058 # Parent c32f9eeec75445bfbbc55df4c1fcc584d3cf45cd # Available At https://bitbucket.org/quark-zju/hg-draft # hg pull https://bitbucket.org/quark-zju/hg-draft -r 60eb2c2b5196 chgcache: introduce a new global state
The new chgcache module will be used to store some cache state of chg, which is useful to preload repo-related contents and speed up related operations. Motivation: Currently, chg only preloads extensions and one chg server is responsible for multiple repos (to avoid unnecessary memory usage). With the new module, eventually the master chg server will have a state storing multiple components of multiple repos, like the changelog index (with radix tree prebuilt), the dirstate, the phasecache, the bookmarks, the obsstore, etc. Why a new module: The feature is low-level and relatively separate from chgserver (which is focused on client/server stuff). So it's made a new module. It could be used without chg in theory, although it depends on chg practically. This patch only contains very basic "set" and "get" methods. diff --git a/mercurial/chgcache.py b/mercurial/chgcache.py new file mode 100644 --- /dev/null +++ b/mercurial/chgcache.py @@ -0,0 +1,22 @@ +# chgcache.py - caching state for chg +# +# Copyright 2017 Facebook, Inc. +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. + +from __future__ import absolute_import + +_cache = {} + +def get(key): + """look up an entry. returns None if key is not found""" + return _cache.get(key) + +def set(key, value): + """write to the cache. if value is None, remove the entry""" + if value is None: + if key in _cache: + del _cache[key] + else: + _cache[key] = value _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel