| Server IP : 46.17.175.229 / Your IP : 216.73.216.82 Web Server : LiteSpeed System : Linux lt-bnk-web1163.main-hosting.eu 4.18.0-553.157.1.lve.el8.x86_64 #1 SMP Mon Aug 24 17:05:39 UTC 2026 x86_64 User : u528038015 ( 528038015) PHP Version : 8.2.33 Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail MySQL : OFF | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /opt/alt/python37/lib/python3.7/site-packages/jsons/ |
Upload File : |
"""
PRIVATE MODULE: do not import (from) it directly.
This module contains functionality for caching functions.
"""
from collections import deque
from functools import lru_cache, update_wrapper
from typing import Callable
class _Wrapper:
"""
A wrapper around a function that needs to be cached. This wrapper allows
for a single point from which cache can be cleared.
"""
instances = deque([])
def __init__(self, wrapped):
self.wrapped = wrapped
self.instances.append(self)
@lru_cache(typed=True)
def __call__(self, *args, **kwargs):
return self.wrapped(*args, **kwargs)
def cached(decorated: Callable):
"""
Alternative for ``functools.lru_cache``. By decorating a function with
``cached``, you can clear the cache of that function by calling
``clear()``.
:param decorated: the decorated function.
:return: a wrapped function.
"""
wrapper = _Wrapper(decorated)
update_wrapper(wrapper=wrapper, wrapped=decorated)
return wrapper
def clear():
"""
Clear all cache of functions that were cached using ``cached``.
:return: None.
"""
for w in _Wrapper.instances:
w.__call__.cache_clear()