Ejemplo n.º 1
0
    def process_view(self, request, view_func, view_args, view_kwargs):
        # TODO: In DEV don't try to grab media out of the cache.
        if settings.DEBUG and "." in request.path:
            return

        response = None
        if request.method == "GET":
            prefix_key = get_prefix_cache_key(request)
            prefix = cache.get(prefix_key, "0")

            response_key = get_response_cache_key(prefix, request)
            response = cache.get(response_key)

        if response is None:
            response = view_func(request, *view_args, **view_kwargs)

        if response['content-type'].startswith('text/html'):
            t = Template(response.content)
            response.content = t.render(RequestContext(request))

        # TODO: This problem has to do with a conflict between this caching
        #       and the built in cache middleware.
        # TODO: Safari is caching pages for too long!
        #       These headers help it forget ...
        response['Cache-Control'] = "private"
        response['Expires'] = "Thu, 1 Jan 70 00:00:00 GMT"
        return response
Ejemplo n.º 2
0
 def process_view(self, request, view_func, view_args, view_kwargs):
     # TODO: In DEV don't try to grab media out of the cache.
     if settings.DEBUG and "." in request.path:
         return
     
     response = None
     if request.method == "GET":
         prefix_key = get_prefix_cache_key(request)
         prefix = cache.get(prefix_key, "0")
         
         response_key = get_response_cache_key(prefix, request)
         response = cache.get(response_key)
     
     if response is None:
         response = view_func(request, *view_args, **view_kwargs)
     
     if response['content-type'].startswith('text/html'):
         t = Template(response.content)
         response.content = t.render(RequestContext(request))
     
     # TODO: This problem has to do with a conflict between this caching
     #       and the built in cache middleware.
     # TODO: Safari is caching pages for too long!
     #       These headers help it forget ...
     response['Cache-Control'] = "private"    
     response['Expires'] = "Thu, 1 Jan 70 00:00:00 GMT"
     return response
Ejemplo n.º 3
0
    def invalidate_cache(self):
        from snapboard.utils import get_prefix_cache_key
        
        prefix = int(time.time())

        cslug = self.thread.category.slug
        tslug = self.thread.slug

        # Views to clear:
        paths = [
            reverse('sb_category_list'),
            reverse('sb_thread_list'),
            reverse('sb_category', args=[cslug]),
            reverse('sb_thread', args=[cslug, tslug])
        ]
        
        for path in paths:
            prefix_key = get_prefix_cache_key(path)
            cache.set(prefix_key, prefix)
Ejemplo n.º 4
0
    def invalidate_cache(self):
        from snapboard.utils import get_prefix_cache_key

        prefix = int(time.time())

        cslug = self.thread.category.slug
        tslug = self.thread.slug

        # Views to clear:
        paths = [
            reverse('sb_category_list'),
            reverse('sb_thread_list'),
            reverse('sb_category', args=[cslug]),
            reverse('sb_thread', args=[cslug, tslug])
        ]

        for path in paths:
            prefix_key = get_prefix_cache_key(path)
            cache.set(prefix_key, prefix)