From 8bae16e302b044b54d8aa547a5ae348e69fc2f21 Mon Sep 17 00:00:00 2001 From: Stephanie Gott <13060286+stephaniegott@users.noreply.github.com> Date: Mon, 6 May 2019 14:00:57 -0600 Subject: [PATCH] [EP-651] remove storage.cache (#4401) GitOrigin-RevId: 91a60f7b3cdc558026476a9845cda1a50b86fc8a --- descarteslabs/client/services/__init__.py | 2 +- .../client/services/storage/__init__.py | 3 +- .../client/services/storage/cache.py | 43 ------------------- 3 files changed, 2 insertions(+), 46 deletions(-) delete mode 100755 descarteslabs/client/services/storage/cache.py diff --git a/descarteslabs/client/services/__init__.py b/descarteslabs/client/services/__init__.py index c6d5e71f..e182e368 100644 --- a/descarteslabs/client/services/__init__.py +++ b/descarteslabs/client/services/__init__.py @@ -16,7 +16,7 @@ from descarteslabs.client.services.metadata import Metadata from descarteslabs.client.services.places import Places from descarteslabs.client.services.raster import Raster -from descarteslabs.client.services.storage import Storage, cached +from descarteslabs.client.services.storage import Storage from descarteslabs.client.services.catalog import Catalog from descarteslabs.client.services.tasks import AsyncTasks, Tasks, FutureTask, CloudFunction from descarteslabs.client.services.vector import Vector diff --git a/descarteslabs/client/services/storage/__init__.py b/descarteslabs/client/services/storage/__init__.py index 621fc94c..3feab387 100644 --- a/descarteslabs/client/services/storage/__init__.py +++ b/descarteslabs/client/services/storage/__init__.py @@ -1,4 +1,3 @@ -from .cache import cached from .storage import Storage -__all__ = ["Storage", "cached"] +__all__ = ["Storage"] diff --git a/descarteslabs/client/services/storage/cache.py b/descarteslabs/client/services/storage/cache.py deleted file mode 100755 index d5a86b95..00000000 --- a/descarteslabs/client/services/storage/cache.py +++ /dev/null @@ -1,43 +0,0 @@ -import cloudpickle -from hashlib import sha1 -import logging -import time -import inspect - - -def cached(storage_client, minimum_runtime=0.0): - def qualified_cached(f): - FUNC_HASH = ( - sha1("".join(inspect.getsourcelines(f)[0][1:])).hexdigest().encode("utf-8") - ) - - def wrapper(*args, **kwargs): - h = "/".join( - [ - FUNC_HASH, - sha1(cloudpickle.dumps((args, kwargs))).hexdigest().encode("utf-8"), - ] - ) - - # Check cache - try: - cached_result = storage_client.get(h, storage_type="cache") - result = cloudpickle.loads(cached_result) - logging.debug("Using cached result") - return result - except BaseException: - pass - - t1 = -time.time() - result = f(*args, **kwargs) - t1 += time.time() - - if t1 > minimum_runtime: - storage_client.set(h, cloudpickle.dumps(result), storage_type="cache") - logging.debug("Cached result") - - return result - - return wrapper - - return qualified_cached