How to use the cachier.base_core._BaseCore function in cachier

To help you get started, we’ve selected a few cachier 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 shaypal5 / cachier / cachier / pickle_core.py View on Github external
from watchdog.events import PatternMatchingEventHandler

# Altenative:  https://github.com/WoLpH/portalocker

from .base_core import _BaseCore

try:
    FileNotFoundError
except NameError:  # we're on python 2
    FileNotFoundError = IOError  # skipcq: PYL-W0622


DEF_CACHIER_DIR = '~/.cachier/'


class _PickleCore(_BaseCore):
    """The pickle core class for cachier.

    Parameters
    ----------
    stale_after : datetime.timedelta, optional
        See _BaseCore documentation.
    next_time : bool, optional
        See _BaseCore documentation.
    pickle_reload : bool, optional
        See core.cachier() documentation.
    cache_dir : str, optional.
        See core.cachier() documentation.
    """

    class CacheChangeHandler(PatternMatchingEventHandler):
        """Handles cache-file modification events."""
github shaypal5 / cachier / cachier / mongo_core.py View on Github external
from pymongo.errors import OperationFailure
    from bson.binary import Binary  # to save binary data to mongodb
except ImportError:  # pragma: no cover
    pass

from .base_core import _BaseCore


MONGO_SLEEP_DURATION_IN_SEC = 1


class RecalculationNeeded(Exception):
    pass


class _MongoCore(_BaseCore):

    _INDEX_NAME = 'func_1_key_1'

    def __init__(self, mongetter, stale_after, next_time):
        if 'pymongo' not in sys.modules:
            warnings.warn((
                "Cachier warning: pymongo was not found. "
                "MongoDB cores will not function."))
        _BaseCore.__init__(self, stale_after, next_time)
        self.mongetter = mongetter
        self.mongo_collection = self.mongetter()
        index_inf = self.mongo_collection.index_information()
        if _MongoCore._INDEX_NAME not in index_inf:
            func1key1 = IndexModel(
                keys=[('func', ASCENDING), ('key', ASCENDING)],
                name=_MongoCore._INDEX_NAME)