-
Notifications
You must be signed in to change notification settings - Fork 0
add: cached get_base_directories #889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+64
−8
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c70a8a2
added cache func and cached get_base_directories
TheMihMih 6e41433
refactor: change get_base_directories output to dto
TheMihMih 97a9824
refactor: deleted has_expired_sqla_objs
TheMihMih ded6d9d
add: dtos file
TheMihMih 097e5f9
refactor: add invalidation
TheMihMih 1ded88e
refactor: add separate cache file
TheMihMih 1f1e034
add: add cache clear to modify_dn
TheMihMih 4ddfab9
Merge remote-tracking branch 'origin/dev' into cached_get_base_direct…
TheMihMih 36caf00
refactor: delete cache clear from modify_dn
TheMihMih 5803347
Merge remote-tracking branch 'origin/dev' into cached_get_base_direct…
TheMihMih 86b2778
fix: delete field
TheMihMih ebe000c
refactor: deleted directory dto
TheMihMih 229b885
refactor: deleted directory dto file
TheMihMih 3b31ef0
refactor: deleted directory dto file from pyproject
TheMihMih d9b361a
refactor: rework to expunge
TheMihMih File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,43 @@ | ||
| """Async cache implementation.""" | ||
|
|
||
| import time | ||
| from functools import wraps | ||
| from typing import Callable, Generic, TypeVar | ||
|
|
||
| from entities import Directory | ||
|
|
||
| T = TypeVar("T") | ||
| DEFAULT_CACHE_TIME = 5 * 60 # 5 minutes | ||
|
|
||
|
|
||
| class AsyncTTLCache(Generic[T]): | ||
| def __init__(self, ttl: int | None = DEFAULT_CACHE_TIME) -> None: | ||
| self._ttl = ttl | ||
| self._value: T | None = None | ||
| self._expires_at: float | None = None | ||
|
|
||
| def clear(self) -> None: | ||
| self._value = None | ||
| self._expires_at = None | ||
|
|
||
| def __call__(self, func: Callable) -> Callable: | ||
| @wraps(func) | ||
| async def wrapper(*args: tuple, **kwargs: dict) -> T: | ||
| if self._value is not None: | ||
| if not self._expires_at or self._expires_at > time.monotonic(): | ||
| return self._value | ||
| self.clear() | ||
|
|
||
| result = await func(*args, **kwargs) | ||
|
|
||
| self._value = result | ||
| self._expires_at = ( | ||
| time.monotonic() + self._ttl if self._ttl else None | ||
| ) | ||
|
|
||
| return result | ||
|
|
||
| return wrapper | ||
|
|
||
|
|
||
| base_directories_cache = AsyncTTLCache[list[Directory]]() |
This file contains hidden or 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
Submodule interface
updated
from f31962 to 95ed5e
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.