Exemplo n.º 1
0
    def rem(self, node, key=CacheWildCard(), coordinates=CacheWildCard()):
        """Delete cached data for this node.

        Parameters
        ------------
        node : Node
            node requesting storage.
        key : str, optional
            Delete only cached objects with this key.
        coordinates : :class:`podpac.Coordinates`
            Delete only cached objects for these coordinates.
        """

        if not hasattr(_thread_local, "cache"):
            _thread_local.cache = {}

        node_key = node.json

        if not isinstance(coordinates, CacheWildCard):
            coordinates_key = coordinates.json if coordinates is not None else None

        # loop through keys looking for matches
        rem_keys = []
        for nk, k, ck in _thread_local.cache.keys():
            if nk != node_key:
                continue
            if not isinstance(key, CacheWildCard) and k != key:
                continue
            if not isinstance(coordinates, CacheWildCard) and ck != coordinates_key:
                continue

            rem_keys.append((nk, k, ck))

        for k in rem_keys:
            del _thread_local.cache[k]
Exemplo n.º 2
0
 def search(self, node, item=CacheWildCard(), coordinates=CacheWildCard()):
     pattern = self._path_join(
         self._get_node_dir(node),
         self._get_filename_pattern(node, item, coordinates))
     return [
         path for path in glob.glob(pattern) if not path.endswith(".meta")
     ]
Exemplo n.º 3
0
    def rem(self, node, key, coordinates=None, mode="all"):
        """Delete cached data for this node.

        Parameters
        ----------
        node : Node, str
            node requesting storage.
        key : str
            Delete only cached objects with this key. Use `'*'` to match all keys.
        coordinates : :class:`podpac.Coordinates`, str
            Delete only cached objects for these coordinates. Use `'*'` to match all coordinates.
        mode : str
            determines what types of the `CacheStore` are affected. Options: 'ram', 'disk', 'network', 'all'. Default 'all'.
        """

        if not isinstance(node, podpac.Node):
            raise TypeError("Invalid node (must be of type Node, not '%s')" % type(node))

        if not isinstance(key, six.string_types):
            raise TypeError("Invalid key (must be a string, not '%s')" % (type(key)))

        if not isinstance(coordinates, podpac.Coordinates) and coordinates is not None and coordinates != "*":
            raise TypeError("Invalid coordinates (must be '*' or of type 'Coordinates', not '%s')" % type(coordinates))

        if mode not in _CACHE_MODES:
            raise ValueError("Invalid mode (must be one of %s, not '%s')" % (_CACHE_MODES, mode))

        if key == "*":
            key = CacheWildCard()

        if coordinates == "*":
            coordinates = CacheWildCard()

        for c in self._get_cache_stores_by_mode(mode):
            c.rem(node=node, key=key, coordinates=coordinates)
Exemplo n.º 4
0
    def rem(self, node, item=CacheWildCard(), coordinates=CacheWildCard()):
        """Delete cached data for this node.

        Parameters
        ------------
        node : Node
            node requesting storage
        item : str, CacheWildCard, optional
            Delete cached objects item, or any item if `item` is a CacheWildCard.
        coordinates : :class:`podpac.Coordinates`, CacheWildCard, None, optional
            Delete only cached objects for these coordinates, or any coordinates if `coordinates` is a CacheWildCard. `None` specifically indicates entries that do not have coordinates.
        """

        # delete matching cached objects
        for path in self.search(node, item=item, coordinates=coordinates):
            self._remove(path)

        # remove empty node directories
        if not self.search(node):
            path = self._get_node_dir(node=node)
            while self._is_empty(path):
                self._rmtree(path)
                path = self._dirname(path)
Exemplo n.º 5
0
    def search(self, node, item=CacheWildCard(), coordinates=CacheWildCard()):
        """Fileglob to match files that could be storing cached data for specified node,key,coordinates

        Parameters
        ----------
        node : podpac.core.node.Node
        item : str, CacheWildCard
            CacheWildCard indicates to match any key
        coordinates : podpac.core.coordinates.coordinates.Coordinates, CacheWildCard, None
            CacheWildCard indicates to macth any coordinates

        Returns
        -------
        TYPE : str
            Fileglob of existing paths that match the request
        """

        delim = self._delim
        prefix = self._get_node_dir(node)
        prefix = prefix if prefix.endswith(delim) else prefix + delim
        response = self._s3_client.list_objects_v2(Bucket=self._s3_bucket,
                                                   Prefix=prefix,
                                                   Delimiter=delim)

        if response["KeyCount"] > 0:
            obj_names = [
                o["Key"].replace(prefix, "") for o in response["Contents"]
            ]
        else:
            obj_names = []

        node_dir = self._get_node_dir(node)
        obj_names = fnmatch.filter(
            obj_names, self._get_filename_pattern(node, item, coordinates))
        paths = [self._path_join(node_dir, filename) for filename in obj_names]
        return paths
Exemplo n.º 6
0
 def search(self, node, item=CacheWildCard(), coordinates=CacheWildCard()):
     """
     Search for matching cached objects.
     """
     raise NotImplementedError