Skip to content

Commit

Permalink
Merge pull request pyeve#14 from amagdas/disable-cache
Browse files Browse the repository at this point in the history
Disable cache
  • Loading branch information
amagdas committed Sep 2, 2014
2 parents 5fcdc6d + 732081a commit 2db0a04
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Version 0.5

Not released yet.

- [fix] ``utils.weak_date`` always returns a RFC-1123 date (Petr Jašek).
- [change] If-Modified-Since has been disabled on resource (collections)
endpoints. Closes #334.
- [fix] Can't embed a ressource with a custom _id (non ObjectId). Closes #427.
- [fix] Do not follow DATE_FORMAT for HTTP headers. Closes #429 (Olivier
Poitrey).
Expand Down
4 changes: 4 additions & 0 deletions eve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
:copyright: (c) 2014 by Nicola Iarocci.
:license: BSD, see LICENSE for more details.
.. versionchanged:: 0.5
'RFC1123_DATE_FORMAT' added.
.. versionchanged:: 0.4
'META' defaults to '_meta'.
'ERROR' defaults to '_error'.
Expand All @@ -32,6 +35,7 @@

# RFC 1123 (ex RFC 822)
DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
RFC1123_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'

URL_PREFIX = ''
API_VERSION = ''
Expand Down
24 changes: 3 additions & 21 deletions eve/methods/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,13 @@ def get(resource, **lookup):
req = parse_request(resource)
embedded_fields = resolve_embedded_fields(resource, req)

# facilitate cached responses
if req.if_modified_since:
# client has made this request before, has it changed?
# this request does not account for deleted documents!!! (issue #243)
preflight_req = copy.copy(req)
preflight_req.max_results = 1
preflight_req.page = 1

cursor = app.data.find(resource, preflight_req, lookup)
if cursor.count() == 0:
# make sure the datasource is not empty (#243).
if not app.data.is_empty(resource):
# the if-modified-since conditional request returned no
# documents, we send back a 304 Not-Modified, which means that
# the client already has the up-to-date representation of the
# resultset.
status = 304
last_modified = None
return response, last_modified, etag, status

# continue processing the full request
last_update = epoch()

# If-Modified-Since disabled on collections (#334)
req.if_modified_since = None
cursor = app.data.find(resource, req, lookup)

cursor = app.data.find(resource, req, lookup)
for document in cursor:
build_response_document(document, resource, embedded_fields)
documents.append(document)
Expand Down
3 changes: 0 additions & 3 deletions eve/tests/methods/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,6 @@ def test_get_default_sort(self):
response, _ = self.get(self.known_resource)
self.assertEqual(response['_items'][0]['prog'], 0)

def test_get_if_modified_since(self):
self.assertIfModifiedSince(self.known_resource_url)

def test_cache_control(self):
self.assertCacheControl(self.known_resource_url)

Expand Down
11 changes: 6 additions & 5 deletions eve/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@

import eve
import hashlib
import werkzeug.exceptions
from flask import request
from flask import current_app as app
from datetime import datetime, timedelta
from bson.json_util import dumps
import werkzeug.exceptions


RFC1123_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
from eve import RFC1123_DATE_FORMAT


class Config(object):
Expand Down Expand Up @@ -162,7 +160,8 @@ def weak_date(date):
:param date: the date to be adjusted.
"""
return datetime.strptime(date, RFC1123_DATE_FORMAT) + timedelta(seconds=1) if date else None
return datetime.strptime(date, RFC1123_DATE_FORMAT) + \
timedelta(seconds=1) if date else None


def str_to_date(string):
Expand All @@ -181,13 +180,15 @@ def date_to_str(date):
"""
return datetime.strftime(date, config.DATE_FORMAT) if date else None


def date_to_rfc1123(date):
""" Converts a datetime value to the corresponding RFC-1123 string.
:param date: the datetime value to convert.
"""
return datetime.strftime(date, RFC1123_DATE_FORMAT) if date else None


def home_link():
""" Returns a link to the API entry point/home page.
Expand Down

0 comments on commit 2db0a04

Please sign in to comment.