How to use the cachelib.FileSystemCache function in cachelib

To help you get started, we’ve selected a few cachelib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github valhallasw / gerrit-patch-uploader / app.py View on Github external
os.chdir(FILE_DIR)

import config  # noqa, needs to be loaded from local path

GIT_PATH = 'git'
PATCH_PATH = 'patch'
RUN_ENV = {'PATH': FILE_DIR + "/bin", 'LANG': 'en_US.UTF-8', 'LD_LIBRARY_PATH': FILE_DIR + "/lib"}

app = Flask(__name__)
app.secret_key = config.app_secret_key

mwoauth = MWOAuth(consumer_key=config.oauth_key, consumer_secret=config.oauth_secret)
mwoauth.handshaker.user_agent = 'Gerrit-Patch-Uploader by valhallasw using MWOAuth - http://tools.wmflabs.org/gerrit-patch-uploader'
app.register_blueprint(mwoauth.bp)

cache = FileSystemCache('cache')


def get_projects():
    projects = cache.get('projects')
    if projects is None:
        p = subprocess.Popen(['ssh', 'gerrit', 'gerrit ls-projects'], stdout=subprocess.PIPE, env=RUN_ENV)
        stdout, stderr = p.communicate()
        projects = stdout.decode("utf-8", "replace").strip().split("\n")
        cache.set('projects', projects)
    return projects


@app.route("/")
def index():
    author = session.get('author', '')
    return render_template('index.html', projects=get_projects(), username=mwoauth.get_current_user(),
github gleitz / howdoi / howdoi / howdoi.py View on Github external
def _clear_cache():
    global cache
    if not cache:
        cache = FileSystemCache(CACHE_DIR, CACHE_ENTRY_MAX, 0)

    return cache.clear()
github gleitz / howdoi / howdoi / howdoi.py View on Github external
BLOCKED_QUESTION_FRAGMENTS = (
    'webcache.googleusercontent.com',
)

STAR_HEADER = u('\u2605')
ANSWER_HEADER = u('{2}  Answer from {0} {2}\n{1}')
NO_ANSWER_MSG = '< no answer given >'

CACHE_EMPTY_VAL = "NULL"
CACHE_DIR = appdirs.user_cache_dir('howdoi')
CACHE_ENTRY_MAX = 128

if os.getenv('HOWDOI_DISABLE_CACHE'):
    cache = NullCache()  # works like an always empty cache
else:
    cache = FileSystemCache(CACHE_DIR, CACHE_ENTRY_MAX, default_timeout=0)

howdoi_session = requests.session()


class BlockError(RuntimeError):
    pass


def _random_int(width):
    bres = os.urandom(width)
    if sys.version < '3':
        ires = int(bres.encode('hex'), 16)
    else:
        ires = int.from_bytes(bres, 'little')

    return ires

cachelib

A collection of cache libraries in the same API interface.

BSD-3-Clause
Latest version published 11 days ago

Package Health Score

94 / 100
Full package analysis

Similar packages