Skip to content

Commit

Permalink
Merge pull request #103 from stckme/secondary_key_cache
Browse files Browse the repository at this point in the history
Fixed get_by_secondary_key of CachedModel
  • Loading branch information
gauravr committed Jan 20, 2024
2 parents d85eea9 + 3c62b62 commit 9907adb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
History
=======

0.93.1 (2023-01-20)
-------------------
* Fixed get_by_secondary_key of CachedModel

0.93.0 (2023-01-19)
-------------------
* Added secondary_key support for CachedModel
Expand Down
2 changes: 1 addition & 1 deletion apphelpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__author__ = """Scroll Tech"""
__email__ = "[email protected]"
__version__ = "0.93.0"
__version__ = "0.93.1"
10 changes: 5 additions & 5 deletions apphelpers/utilities/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _prefix_key(cls, data: dict) -> str:
return key

@classmethod
def _secondary_key_prefix(cls, data: dict) -> str:
def _secondary_prefix_key(cls, data: dict) -> str:
key = f"{cls.ns}:_sk_"
for _field in cls.secondary_key_fields:
key += f":{data.get(_field, '*')}"
Expand All @@ -50,7 +50,7 @@ def get(cls, **data: Any) -> Optional[dict]:

@classmethod
def get_by_secondary_key(cls, **data: Any) -> Optional[dict]:
secondary_key = cls._secondary_key_prefix(**data)
secondary_key = cls._secondary_prefix_key(data)
primary_key = cls.connection.get(secondary_key)
if primary_key:
value = cls.connection.get(primary_key)
Expand Down Expand Up @@ -90,7 +90,7 @@ def create(cls, **data: Any) -> str:

@classmethod
def add_secondary_key(cls, primary_key: str, **data: Any) -> str:
secondary_key = cls._secondary_key_prefix(data)
secondary_key = cls._secondary_prefix_key(data)
cls.connection.set(secondary_key, primary_key)
return secondary_key

Expand Down Expand Up @@ -134,7 +134,7 @@ def delete(cls, **data):

@classmethod
def delete_secondary_key(cls, **data: Any):
secondary_key = cls._secondary_key_prefix(data)
secondary_key = cls._secondary_prefix_key(data)
cls.connection.delete(secondary_key)

@classmethod
Expand All @@ -145,6 +145,6 @@ def delete_all(cls, **data):

@classmethod
def delete_all_secondary_keys(cls):
secondary_keys = cls.connection.keys(cls._secondary_key_prefix(data={}))
secondary_keys = cls.connection.keys(cls._secondary_prefix_key(data={}))
if secondary_keys:
cls.connection.delete(*secondary_keys)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.93.0
current_version = 0.93.1
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
test_suite="tests",
tests_require=test_requirements,
url="https://github.com/scrolltech/apphelpers",
version="0.93.0",
version="0.93.1",
zip_safe=False,
)

0 comments on commit 9907adb

Please sign in to comment.