Skip to main content

Build Status codecov Documentation Status License

Falcon-Caching

This library provides cache support for the Falcon web framework.

It is a port of the popular Flask-Caching library.

The library aims to be compatible with CPython 3.6+ and PyPy 3.5+.

Documentation

You can find the documentation of this library on Read the Docs.

Quickstart

Quick example:

import falcon
from falcon_caching import Cache

# setup the cache instance
cache = Cache(
    config=
    {
        'CACHE_EVICTION_STRATEGY': 'time-based',  # how records are evicted
        'CACHE_TYPE': 'simple'  # what backend to use to store the cache
    })

class ThingsResource:
    # mark the method as cached
    @cache.cached(timeout=600)
    def on_get(self, req, resp):
        pass

# add the cache middleware to the Falcon app
app = falcon.API(middleware=cache.middleware)

things = ThingsResource()

app.add_route('/things', things)

Alternatively you could cache the whole resource:

# mark the whole resource - all its 'on_' methods as cached
@cache.cached(timeout=600)
class ThingsResource:
    def on_get(self, req, resp):
        pass

    def on_post(self, req, resp):
        pass

NOTE:
Be careful with the order of middlewares. The cache.middleware will short-circuit any further processing if a cached version of that resource is found. It will skip any remaining process_request and process_resource methods, as well as the responder method that the request would have been routed to. However, any process_response middleware methods will still be called.

This is why it is suggested that you add the cache.middleware following any authentication / authorization middlewares to avoid unauthorized access of records served from the cache.

Development

For the development environment we use Pipenv and for packaging we use Flit.

Documentation

The documentation is built via Sphinx following the Google docstring style and hosted on Read the Docs.

To review the documentation locally before committing:

$ cd docs
$ python -m http.server 8088

Now you can access the documentation locally under http://127.0.0.1:8088/_build/html/

Development environment

To be able to test memcached the pylibmc library should be installed, which requires the memcached source to compile, so you will need to install libmemcached-dev first:

$ sudo apt-get install libmemcached-dev

You will also need Memcached, Redis and Redis Sentinel to be installed to be able to test against those locally:

$ sudo apt-get install memcached redis-server redis-sentinel

You will also need Python 3.6-3.8 and PyPy3 and its source package installed to run tox in all environments.

We do use type hinting and run MyPy on those, but unfortunately MyPy currently breaks the PyPy tests due to the typed-ast package's "bug" (see https://github.com/python/typed_ast/issues/97). Also with Pipenv you can't have a second Pipfile. This is why for now we don't have mypy listed as a dev package in the Pipfile.

Credits

As this is a port of the popular Flask-Caching library onto the Falcon web framework, parts of the code is copied from the Flask-Caching library.

Release files for falcon-caching 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for falcon-caching 0.1.0
File Size Uploaded
falcon_caching-0.1.0.tar.gz 34.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for falcon-caching 0.1.0
File Interpreter ABI Platform
falcon_caching-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 57.9 kB

Release files / falcon_caching-0.1.0.tar.gz

Download URL falcon_caching-0.1.0.tar.gz
Size 34.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7f9f8b8dc3abd4661864a5007980f963fdda8e8676dff2fac75e579ef84ef5aa
BLAKE2b-256 checksum
How to use checksums
d5fb65b093c0f84158d55ca763947904b227714bab72c3f77c2d604ad08773c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Release files / falcon_caching-0.1.0-py3-none-any.whl

Download URL falcon_caching-0.1.0-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ccc8e1adeaf034940459896d0a5133af7ed6e2095388730f04141ec70ce2bca2
BLAKE2b-256 checksum
How to use checksums
2692333602a7d27fe8bb11d73a4876cb05d7f4c3a093a3dff07ee21cc2deb799
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.22.0

Release history Release notifications | RSS feed

1.1.0

2 release files

1.0.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page