Skip to content

Commit

Permalink
rename tests file and add examples in README file
Browse files Browse the repository at this point in the history
  • Loading branch information
drgarcia1986 committed Aug 8, 2015
1 parent 8f1199e commit 523ebf3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ flake8:
flake8 muffin_cache/

test: clean flake8
py.test -x --cov-config .coveragerc --cov-report term-missing --cov muffin_cache test.py
py.test -x --cov-config .coveragerc --cov-report term-missing --cov muffin_cache tests.py

test-debug: clean
py.test -x --pdb test.py
py.test -x --pdb tests.py

requirements: clean
pip install -r requirements-dev.txt
Expand Down
44 changes: 43 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,48 @@ Installation
Usage
=====

Add Muffin-Redis_ and Muffin-Cache to muffin plugin list:

.. code-block:: python
import muffin
app = muffin.Application(
'example',
PLUGINS=(
'muffin_redis',
'muffin_cache',
)
)
And use *CacheHandler* for class based views:

.. code-block:: python
from muffin_cache import CacheHandler
@app.register('/cached')
class Example(CacheHandler):
def get(self, request):
return 'text'
Or *cache_view* for functions based views:

.. code-block:: python
from muffin_cache import cache_view
@app.register('/cached')
@cache_view
def example(request):
return 'text'
The cache lifetime is determined by *CACHE_LIFETIME* setting of muffin application.
(the default lifetime is 30 minutes).

.. _bugtracker:

Bug tracker
Expand Down Expand Up @@ -71,7 +113,7 @@ Licensed under a `MIT license`_.


.. _muffin: https://github.com/klen/muffin
.. _muffin-redis: https://github.com/klen/muffin-redis
.. _drgarcia1986: https://github.com/drgarcia1986

.. _MIT license: http://opensource.org/licenses/MIT

4 changes: 2 additions & 2 deletions muffin_cache/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .plugin import Plugin # noqa
from .handler import CachedHandler # noqa
from .utils import cached_view # noqa
from .handler import CacheHandler # noqa
from .utils import cache_view # noqa


__version__ = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion muffin_cache/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from muffin.utils import abcoroutine


class CachedHandler(Handler):
class CacheHandler(Handler):

CACHED_HTTP_METHODS = ('GET', 'OPTIONS')

Expand Down
6 changes: 3 additions & 3 deletions muffin_cache/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .handler import CachedHandler
from .handler import CacheHandler


def cached_view(view, **kwargs):
return CachedHandler.from_view(
def cache_view(view, **kwargs):
return CacheHandler.from_view(
view, kwargs.get('methods', '*'), view.__name__
)
10 changes: 5 additions & 5 deletions test.py → tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import muffin
import pytest

from muffin_cache import CachedHandler, cached_view
from muffin_cache import CacheHandler, cache_view


@pytest.fixture(scope='session')
Expand All @@ -29,7 +29,7 @@ def test_should_cache_response(app, client):
hit_view_count = 0

@app.register('/cache')
class View(CachedHandler):
class View(CacheHandler):

def get(self, request):
nonlocal hit_view_count
Expand All @@ -51,7 +51,7 @@ def test_should_cache_json_response(app, client):
hit_view_count = 0

@app.register('/cache_json')
class View(CachedHandler):
class View(CacheHandler):

def get(self, request):
nonlocal hit_view_count
Expand All @@ -70,7 +70,7 @@ def test_should_cache_function_view(app, client):
hit_view_count = 0

@app.register('/cache_func')
@cached_view
@cache_view
def cached(request):
nonlocal hit_view_count
hit_view_count += 1
Expand All @@ -87,7 +87,7 @@ def test_should_not_cache_unsafe_http_method(app, client):
hit_view_count = 0

@app.register('/dont-cache')
class View(CachedHandler):
class View(CacheHandler):

def post(self, request):
nonlocal hit_view_count
Expand Down

0 comments on commit 523ebf3

Please sign in to comment.