Skip to content

Commit

Permalink
adicionando cache
Browse files Browse the repository at this point in the history
  • Loading branch information
iury committed Jun 8, 2016
1 parent 9e2bc61 commit 9926693
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Flask==0.10.1
Flask-Cache
flask-mongoengine==0.7.5
Flask-RESTful==0.3.5
Flask-Cors==2.1.2
Werkzeug==0.11.10
raise_if
6 changes: 4 additions & 2 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from flask import Flask
from flask.ext.mongoengine import MongoEngine
from flask.ext.cors import CORS
from flask.ext.cache import Cache

app = Flask(__name__)

app = Flask(__name__)
app.config.from_object('src.settings')

enable_cors = app.config.get("ENABLE_CORS", False)
Expand All @@ -15,8 +16,9 @@
})

db = MongoEngine(app)
cache = Cache(config={"CACHE": app.config.get("CACHE_TYPE")})
cache.init_app(app)

from resources import properties
from models.properties import Property

app.register_blueprint(properties.blueprint)
2 changes: 2 additions & 0 deletions src/resources/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from flask_restful import Api, reqparse, abort
from mongoengine import DoesNotExist, ValidationError

from src.app import cache
from src.usecase import spotippos
from src.resources import Resource
from .utils import parse_property_arguments
Expand Down Expand Up @@ -34,6 +35,7 @@ def post(self):
property_ = spotippos.save_property(**args)
return spotippos.get_property(property_.id), 201

@cache.memoize(timeout=100)
def get(self, id=None):
parser = reqparse.RequestParser()
parser.add_argument('ax')
Expand Down
1 change: 1 addition & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
MONGO_PORT = os.getenv("MONGO_PORT", 27017)
DEBUG = os.getenv("DEBUG", False)
ENABLE_CORS = True
CACHE_TYPE="simple"
SECRET_KEY = os.getenv("SECRET_KEY")

0 comments on commit 9926693

Please sign in to comment.