Skip to content

Commit

Permalink
fix: removed prints calls
Browse files Browse the repository at this point in the history
fix: when the original handler is recovered from view now is done correctly. With non-parched version, when you can not concatenate middlewares because the aiohttp-cache middleware assumes that you have not more than 1 middleware.
fix: cache middleware now not assumes that, when a function is not marked with 'cache_enable' property, it has not be cached.
  • Loading branch information
cr0hn committed Dec 5, 2016
1 parent 44d0bd4 commit a179f5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion aiohttp_cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
from .middleware import *
from .exceptions import *

__version__ = "1.0.0"
__version__ = "1.0.1"

18 changes: 9 additions & 9 deletions aiohttp_cache/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@

async def cache_middleware(app, handler):
async def middleware_handler(request):
if getattr(handler, "cache_enable", True):
_handler = request.match_info.handler

if getattr(_handler, "cache_enable", False):
#
# Cache is disabled?
#
if getattr(handler, "cache_unless", False) is True:
print("disable cache")
return await handler(request)
if getattr(_handler, "cache_unless", False) is True:
return await _handler(request)

cache_backend = app["cache"]

key = cache_backend.make_key(request)

if await cache_backend.has(key):
cached_response = await cache_backend.get(key)
print("using cache")
return Response(**cached_response)

#
# Generate cache
#
original_response = await handler(request)
original_response = await _handler(request)

data = dict(status=original_response.status,
headers=dict(original_response.headers),
body=original_response.body)

expires = getattr(handler, "cache_expires", 300)
expires = getattr(_handler, "cache_expires", 300)

await cache_backend.set(key, data, expires)
print("building key")

return original_response

# Not cached
return await handler(request)
return await _handler(request)

return middleware_handler

Expand Down

0 comments on commit a179f5f

Please sign in to comment.