Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 191_add_new_constraint_operators
- Loading branch information
Showing
14 changed files
with
214 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import abc | ||
from typing import Any, Optional | ||
|
||
from fcache.cache import FileCache as _FileCache | ||
|
||
|
||
class BaseCache(abc.ABC): | ||
@abc.abstractmethod | ||
def set(self, key: str, value: Any): | ||
pass | ||
|
||
@abc.abstractmethod | ||
def mset(self, data: dict): | ||
pass | ||
|
||
@abc.abstractmethod | ||
def get(self, key: str, default: Optional[Any] = None): | ||
pass | ||
|
||
@abc.abstractmethod | ||
def exists(self, key: str): | ||
pass | ||
|
||
@abc.abstractmethod | ||
def destroy(self): | ||
pass | ||
|
||
|
||
class FileCache(BaseCache): | ||
def __init__(self, name: str, directory: Optional[str] = None): | ||
self._cache = _FileCache(name, app_cache_dir=directory) | ||
|
||
def set(self, key: str, value: Any): | ||
self._cache[key] = value | ||
self._cache.sync() | ||
|
||
def mset(self, data: dict): | ||
self._cache.update(data) | ||
self._cache.sync() | ||
|
||
def get(self, key: str, default: Optional[Any] = None): | ||
return self._cache.get(key, default) | ||
|
||
def exists(self, key: str): | ||
return key in self._cache | ||
|
||
def destroy(self): | ||
return self._cache.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
**************************************** | ||
Cache | ||
**************************************** | ||
|
||
.. autoclass:: UnleashClient.cache.BaseCache | ||
|
||
.. automethod:: set | ||
|
||
.. automethod:: mset | ||
|
||
.. automethod:: get | ||
|
||
.. automethod:: exists | ||
|
||
.. automethod:: destroy |
Oops, something went wrong.