2011-03-03 3 views
2

특정 컨트롤러 액션에 대한 beaker_cache 장식에 의해 생성 된 캐시를 무효화해야합니다Pylons에서 beaker_cache를 무효화하는 방법은 무엇입니까?

from pylons.decorators.cache import beaker_cache 

class SampleController(BaseController): 

    @beaker_cache() 
    def home(self): 
     c.data = expensive_call() 
     return render('/home.myt') 

    def __clear_home_cache(self): 
     pass 

내가 __clear_home_cache 함수 내에서 region_invalidate()를 사용할 수 있습니까?

답변

1

beaker_cache 데코레이터로 캐시 된 항목을 무효화하는 방법을 확인하는 한 가지 방법은 그것이 작동하는 방식과 수행하는 방식을 살펴 보는 것입니다. GitHub에 pylons.decorators.cache 모듈, here's the corresponding source file에 정의되어 있습니다.

은 기본적으로 당신은 네임 스페이스캐시 특정 컨트롤러 액션에 대한 키를 선택하는 로직을 찾고 있습니다. 해당 파일의 create_cache_key() 함수에 의해 수행됩니다. 덧붙여 말하자면이 함수에는 유용한 주석이 있습니다.

Example: 
    from pylons import cache 
    from pylons.decorators.cache import create_cache_key 
    namespace, key = create_cache_key(MyController.some_method) 
    cache.get_cache(namespace).remove(key) 
관련 문제