move last_modified fields into memcache db

This commit is contained in:
spez
2009-02-05 11:04:42 -08:00
parent 9e31995570
commit 9a89f8b895
3 changed files with 16 additions and 12 deletions

View File

@@ -241,6 +241,7 @@ class ApiController(RedditController):
#update the modified flags
set_last_modified(c.user, 'overview')
set_last_modified(c.user, 'submitted')
set_last_modified(c.user, 'liked')
# flag search indexer that something has changed
tc.changed(l)

View File

@@ -574,7 +574,7 @@ class RedditController(BaseController):
return
date = utils.is_modified_since(thing, action, request.if_modified_since)
if date is True:
if date is False:
abort(304, 'not modified')
else:
c.response.headers['Last-Modified'] = http_utils.http_date_str(date)

View File

@@ -6,27 +6,30 @@ def make_last_modified():
last_modified = last_modified.replace(microsecond = 0)
return last_modified
def last_modified_key(thing, action):
return 'last_' + action + '_' + thing._fullname
def is_modified_since(thing, action, date):
"""Returns true if the date is older than the last_[action] date,
which means a 304 should be returned. Otherwise returns the date
that should be sent as the last-modified header."""
from pylons import g
cache = g.permacache
prop = 'last_' + action
if not hasattr(thing, prop):
key = last_modified_key(thing, action)
last_modified = cache.get(key)
if not last_modified:
#if there is no last_modified, add one
last_modified = make_last_modified()
setattr(thing, prop, last_modified)
thing._commit()
else:
last_modified = getattr(thing, prop)
cache.set(key, last_modified)
if not date or date < last_modified:
return last_modified
#if a date was passed in and it's equal to last modified
return True
else:
#if a date was passed in and it's >= to last modified
return False
def set_last_modified(thing, action):
from pylons import g
setattr(thing, 'last_' + action, make_last_modified())
thing._commit()
key = last_modified_key(thing, action)
g.permacache.set(key, make_last_modified())