캐싱은 더 이상 힘들 필요가 없습니다. 몇 줄의 코드만으로 Omoide Cache는 즉시 Python 서비스를 다음 단계로 가져옵니다!
출시 된 도서관 : PYPI
소스 코드 : Github
튜토리얼 №1 : 내 블로그 또는 매체
이것은 의존성이없는 순수한 파이썬으로 작성된 강력하고 조정하기 쉬우 며 통합하기 쉬운 메모리 캐시 솔루션입니다.
메소드 레벨 캐시로, 메소드 호출 인수를 캐시 키로 사용하여 단일 클래스 메소드를 감싸고 리턴 값을 저장하도록 설계되었습니다.
특정 사용 사례에 맞게 사용자 정의 할 수있는 다양한 만료 및 새로 고침 옵션을 제공합니다.
매우 사용자 친화적이며 간단한 데코레이터 (즉, 주석, Java에서 나오는 사람들의 경우)와 통합하기가 매우 쉽습니다. 코드에 복잡한 논리를 추가 할 필요가 없으며 서비스의 모든 방법 위에 @omoide_cache() 사용하십시오. 기본 설정으로 메소드의 캐시를 자동 생성합니다. 데코레이터 매개 변수를 통해 이러한 설정을 추가로 조정할 수 있습니다.
공정한 경고 -이 프로젝트는 수명주기의 초기 단계에 있으며 향후 많은 개선 및 버그 수정이있을 것입니다. 모든 제안 및 버그 보고서는 매우 환영합니다!
pip install omoide-cachegit clone https://github.com/jpleorx/omoide-cache.git
cd omoide-cache
pip install --editable . import time
from omoide_cache import omoide_cache
# A class where cache was added to a simulated long running method
class ExampleService :
@ omoide_cache ()
def time_consuming_method ( self , x : int ) -> int :
time . sleep ( 2.0 )
return x * x
service = ExampleService ()
# The first call will execute real logic and store the result in cache
service . time_consuming_method ( 1 )
# The second call will get results from cache
service . time_consuming_method ( 1 )여기에 캐시가 너무 커질 때 가장 자주 액세스 할 수있는 항목을 떨어 뜨리는 캐시를 추가합니다.
import time
from omoide_cache import omoide_cache , ExpireMode
class ExampleService :
@ omoide_cache ( max_allowed_size = 10 , size_expire_mode = ExpireMode . ACCESS_COUNT_BASED )
def time_consuming_method ( self , x : int ) -> int :
time . sleep ( 2.0 )
return x * x 여기서 캐시는 2 분 전에 마지막으로 액세스 한 품목을 자동으로 제거합니다.
import time
from omoide_cache import omoide_cache
class ExampleService :
@ omoide_cache ( expire_by_access_duration_s = 120 )
def time_consuming_method ( self , x : int ) -> int :
time . sleep ( 2.0 )
return x * x또는 2 분 전에 계산 된 품목을 제거 할 수 있습니다.
import time
from omoide_cache import omoide_cache
class ExampleService :
@ omoide_cache ( expire_by_computed_duration_s = 120 )
def time_consuming_method ( self , x : int ) -> int :
time . sleep ( 2.0 )
return x * x 여기서 캐시는 2 분 전에 계산 된 항목을 비동기로 새로 고칠 것입니다. 새로 고침 시도는 10 초마다 수행됩니다.
import time
from omoide_cache import omoide_cache , RefreshMode
class ExampleService :
@ omoide_cache ( refresh_duration_s = 120 , refresh_period_s = 10 , refresh_mode = RefreshMode . INDEPENDENT )
def time_consuming_method ( self , x : int ) -> int :
time . sleep ( 2.0 )
return x * x@omoide_cache() 사용하지만 @omoide_cache 사용하지 않습니다. 나는 솔직히 데코레이터 에이 이상한 행동이 왜이 이상한 행동이 있는지, 나중에 업데이트에서 최선을 다할 것입니다.내 다른 작업을 확인하거나 저에게 연락하려는 경우 :