How to use the cachelib.NullCache 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 eilbecklab / clinvar-miner / clinvar-miner.py View on Github external
from datetime import datetime
from db import DB
from flask import Flask
from flask import Response
from flask import abort
from flask import redirect
from flask import request
from json import JSONEncoder
from hashlib import sha256
from os import environ
from urllib.parse import urlparse, quote
from werkzeug.routing import BaseConverter

app = Flask(__name__)
ttl = float(environ.get('TTL', 0)) #zero means infinity to the FileSystemCache
cache = FileSystemCache('/tmp/clinvar-miner', threshold=1000000) if ttl >= 0 else NullCache()
cache.clear() #delete the cache when the webserver is restarted

app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True

clinvar_versions = DB().dates()

#it's necessary to double-escape slashes because WSGI decodes them before passing the URL to Flask
class SuperEscapedConverter(BaseConverter):
    @staticmethod
    def to_python(value):
        return value.replace('%2F', '/')

    @staticmethod
    def to_url(value):
        return quote(value).replace('/', '%252F')
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')

cachelib

A collection of cache libraries in the same API interface.

BSD-3-Clause
Latest version published 7 months ago

Package Health Score

89 / 100
Full package analysis