From 9b34c2a105dd076870159341099e6aff72c0aa1b Mon Sep 17 00:00:00 2001 From: Claudio Date: Wed, 13 Jul 2016 13:40:49 -0300 Subject: [PATCH 1/2] Change deprecated name import flask.ext.cache to flask_cache --- docs/index.rst | 8 ++++---- examples/hello.py | 2 +- flask_cache/__init__.py | 2 +- flask_cache/jinja2ext.py | 2 +- test_cache.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 2ed3a23..3a50324 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,7 +1,7 @@ Flask-Cache ================ -.. module:: flask.ext.cache +.. module:: flask_cache Installation ------------ @@ -20,7 +20,7 @@ Set Up Cache is managed through a ``Cache`` instance:: from flask import Flask - from flask.ext.cache import Cache + from flask_cache import Cache app = Flask(__name__) # Check Configuring Flask-Cache section for more details @@ -167,7 +167,7 @@ Set timeout to "del" to delete cached value:: If keys are provided, you may easily generate the template fragment key and delete it from outside of the template context:: - from flask.ext.cache import make_template_fragment_key + from flask_cache import make_template_fragment_key key = make_template_fragment_key("key1", vary_on=["key2", "key3"]) cache.delete(key) @@ -192,7 +192,7 @@ Here's an example script to empty your application's cache: .. code-block:: python - from flask.ext.cache import Cache + from flask_cache import Cache from yourapp import app, your_cache_config diff --git a/examples/hello.py b/examples/hello.py index abb068c..7f7a543 100644 --- a/examples/hello.py +++ b/examples/hello.py @@ -2,7 +2,7 @@ from datetime import datetime from flask import Flask, jsonify -from flask.ext.cache import Cache +from flask_cache import Cache app = Flask(__name__) diff --git a/flask_cache/__init__.py b/flask_cache/__init__.py index 85d90e3..ffe62a5 100644 --- a/flask_cache/__init__.py +++ b/flask_cache/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ - flask.ext.cache + flask_cache ~~~~~~~~~~~~~~ Adds cache support to your application. diff --git a/flask_cache/jinja2ext.py b/flask_cache/jinja2ext.py index 73be6ac..6d85fe7 100644 --- a/flask_cache/jinja2ext.py +++ b/flask_cache/jinja2ext.py @@ -30,7 +30,7 @@ from jinja2 import nodes from jinja2.ext import Extension -from flask.ext.cache import make_template_fragment_key +from flask_cache import make_template_fragment_key JINJA_CACHE_ATTR_NAME = '_template_fragment_cache' diff --git a/test_cache.py b/test_cache.py index 9811572..752ffa2 100644 --- a/test_cache.py +++ b/test_cache.py @@ -7,7 +7,7 @@ import string from flask import Flask, render_template, render_template_string -from flask.ext.cache import Cache, function_namespace, make_template_fragment_key +from flask_cache import Cache, function_namespace, make_template_fragment_key if sys.version_info < (2,7): import unittest2 as unittest From 6b8a7137c14f2ef84e1e960cf4dd454c57156752 Mon Sep 17 00:00:00 2001 From: Claudio Date: Wed, 13 Jul 2016 16:20:53 -0300 Subject: [PATCH 2/2] updating form of import Flask -Cache module. --- docs/index.rst | 22 +++++++++++++++++++++- examples/hello.py | 11 ++++++++--- flask_cache/__init__.py | 2 +- flask_cache/jinja2ext.py | 9 ++++++++- test_cache.py | 10 ++++++++-- 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 2ed3a23..aa11390 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,7 +1,7 @@ Flask-Cache ================ -.. module:: flask.ext.cache +.. module:: flask_cache Installation ------------ @@ -20,8 +20,13 @@ Set Up Cache is managed through a ``Cache`` instance:: from flask import Flask + + # if Flask version < 0.11.0 from flask.ext.cache import Cache + # if Flask version >= 0.11.0 + from flask_cache import Cache + app = Flask(__name__) # Check Configuring Flask-Cache section for more details cache = Cache(app,config={'CACHE_TYPE': 'simple'}) @@ -167,7 +172,16 @@ Set timeout to "del" to delete cached value:: If keys are provided, you may easily generate the template fragment key and delete it from outside of the template context:: + + # if Flask version < 0.11.0 from flask.ext.cache import make_template_fragment_key + + # if Flask version >= 0.11.0 + from flask_cache import make_template_fragment_key + + + + key = make_template_fragment_key("key1", vary_on=["key2", "key3"]) cache.delete(key) @@ -192,8 +206,14 @@ Here's an example script to empty your application's cache: .. code-block:: python + # if Flask version < 0.11.0 from flask.ext.cache import Cache + # if Flask version >= 0.11.0 + from flask_cache import Cache + + + from yourapp import app, your_cache_config cache = Cache() diff --git a/examples/hello.py b/examples/hello.py index abb068c..399b0d4 100644 --- a/examples/hello.py +++ b/examples/hello.py @@ -1,15 +1,20 @@ import random from datetime import datetime -from flask import Flask, jsonify -from flask.ext.cache import Cache +from flask import Flask,__version__, jsonify + +if tuple( map(int, __version__.split("."))) >= (0,11,0): + from flask_cache import Cache +else: + from flask.ext.cache import Cache + app = Flask(__name__) app.config.from_pyfile('hello.cfg') cache = Cache(app) -#: This is an example of a cached view +#: This is an example of a cached view @app.route('/api/now') @cache.cached(50) def current_time(): diff --git a/flask_cache/__init__.py b/flask_cache/__init__.py index 85d90e3..ffe62a5 100644 --- a/flask_cache/__init__.py +++ b/flask_cache/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ - flask.ext.cache + flask_cache ~~~~~~~~~~~~~~ Adds cache support to your application. diff --git a/flask_cache/jinja2ext.py b/flask_cache/jinja2ext.py index 73be6ac..b7e54f7 100644 --- a/flask_cache/jinja2ext.py +++ b/flask_cache/jinja2ext.py @@ -30,7 +30,14 @@ from jinja2 import nodes from jinja2.ext import Extension -from flask.ext.cache import make_template_fragment_key +from flask import __version__ + +if tuple( map(int, __version__.split("."))) >= (0,11,0): + from flask_cache import make_template_fragment_key +else: + from flask.ext.cache import make_template_fragment_key + + JINJA_CACHE_ATTR_NAME = '_template_fragment_cache' diff --git a/test_cache.py b/test_cache.py index 9811572..cdca6b8 100644 --- a/test_cache.py +++ b/test_cache.py @@ -6,8 +6,14 @@ import random import string -from flask import Flask, render_template, render_template_string -from flask.ext.cache import Cache, function_namespace, make_template_fragment_key +from flask import Flask,__version__, render_template, render_template_string + +if tuple( map(int, __version__.split("."))) >= (0,11,0): + from flask_cache import Cache, function_namespace, make_template_fragment_key +else: + from flask.ext.cache import Cache, function_namespace, make_template_fragment_key + + if sys.version_info < (2,7): import unittest2 as unittest