Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
prevent error about memcache key length with long URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Mar 13, 2016
1 parent 0b6d8c3 commit 5eb78be
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions knesset/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
def processor(request):
from django.contrib.flatpages.models import FlatPage
from django.core.cache import cache
page = cache.get('flatpage_block_%s'%request.path)
if not page:
qs = FlatPage.objects.filter(url=request.path)
if qs.exists():
page = qs.values('title', 'content', 'template_name')[0]
else:
page = 'NO PAGE'
cache.set('flatpage_block_%s'%request.path, page, 86400)
d.update({
'flatpage': page if page and page != 'NO PAGE' else None
})
if len(request.path) < 150:
# we limit the length becuase otherwise we get memcache error about key length
page = cache.get('flatpage_block_%s'%request.path)
if not page:
qs = FlatPage.objects.filter(url=request.path)
if qs.exists():
page = qs.values('title', 'content', 'template_name')[0]
else:
page = 'NO PAGE'
cache.set('flatpage_block_%s'%request.path, page, 86400)
d.update({
'flatpage': page if page and page != 'NO PAGE' else None
})
return d

0 comments on commit 5eb78be

Please sign in to comment.