How to use the cachetools.cached function in cachetools

To help you get started, we’ve selected a few cachetools 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 nocproject / noc / tests / test_discovery.py View on Github external
@cachetools.cached(_profile_cache)
def get_profile(name):
    return Profile.get_by_name(name)
github NervanaSystems / ngraph-neon / ngraph / op_graph / op_graph.py View on Github external
def tdcache():
    """
    Decorator to mark tensor description method as cached.

    Returns:
        Cache decorator set to use a particular cache.
    """
    return cachetools.cached(cache=tdcache.tensor_description_cache)
github databand-ai / dbnd / plugins / dbnd-aws / src / dbnd_aws / credentials.py View on Github external
@cached(cache={})
def get_boto_s3_resource():
    session = get_boto_session()
    return session.resource("s3")
github nocproject / noc / sla / models / slaprobe.py View on Github external
    @cachetools.cached(_target_cache, key=lambda x: str(x.id), lock=id_lock)
    def get_target(self):
        mo = ManagedObject.objects.filter(address=self.target)[:1]
        if mo:
            return mo[0]
        return None
github kevinjalbert / notion-toolbox / shared / notionscripts / notion_api.py View on Github external
    @cached(cache={})
    def tags_database(self):
        return self.client().get_collection_view(self.config.tags_database_url())
github costastf / locationsharinglib / locationsharinglib / locationsharinglib.py View on Github external
    @cached(STATE_CACHE)
    def _get_data(self):
        payload = {'authuser': 0,
                   'hl': 'en',
                   'gl': 'us',
                   # pd holds the information about the rendering of the map and
                   # it is irrelevant with the location sharing capabilities.
                   # the below info points to google's headquarters.
                   'pb': ('!1m7!8m6!1m3!1i14!2i8413!3i5385!2i6!3x4095'
                          '!2m3!1e0!2sm!3i407105169!3m7!2sen!5e1105!12m4'
                          '!1e68!2m2!1sset!2sRoadmap!4e1!5m4!1e4!8m2!1e0!'
                          '1e1!6m9!1e12!2i2!26m1!4b1!30m1!'
                          '1f1.3953487873077393!39b1!44e1!50e0!23i4111425')}
        url = 'https://www.google.com/maps/rpc/locationsharing/read'
        response = self._session.get(url, params=payload, verify=True)
        self._logger.debug(response.text)
        if response.ok:
github nocproject / noc / fm / models / alarmclass.py View on Github external
        @cachetools.cached(self._clear_handlers_cache, key=lambda x: x.id, lock=handlers_lock)
        def _get_handlers(alarm_class):
            handlers = []
            for hh in alarm_class.clear_handlers:
                try:
                    h = get_handler(hh)
                except ImportError:
                    h = None
                if h:
                    handlers += [h]
            return handlers
github mideind / Greynir / queries / news.py View on Github external
@cachetools.cached(cachetools.TTLCache(1, _NEWS_CACHE_TTL))
def _get_news_data(max_items=8):
    """ Fetch news headline data from RÚV, preprocess it. """
    res = query_json_api(_NEWS_API)
    if not res or "nodes" not in res or not len(res["nodes"]):
        return None

    items = [
        {"title": i["node"]["title"], "intro": i["node"]["intro"]} for i in res["nodes"]
    ]

    return items[:max_items]
github peterbe / premailer / premailer / cache.py View on Github external
        @cachetools.cached(cache, lock=cache_access_lock)
        @functools.wraps(func)
        def inner(*args, **kwargs):
            return func(*args, **kwargs)