All Projects → cr0hn → aiohttp-cache

cr0hn / aiohttp-cache

Licence: other
A cache system for aiohttp server

Programming Languages

python
139335 projects - #7 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to aiohttp-cache

Pyaiodl
A python Asynchronous Downloader - Pyaiodl
Stars: ✭ 40 (+2.56%)
Mutual labels:  aiohttp
python3-concurrency
Python3爬虫系列的理论验证,首先研究I/O模型,分别用Python实现了blocking I/O、nonblocking I/O、I/O multiplexing各模型下的TCP服务端和客户端。然后,研究同步I/O操作(依序下载、多进程并发、多线程并发)和异步I/O(asyncio)之间的效率差别
Stars: ✭ 49 (+25.64%)
Mutual labels:  aiohttp
homebrew-extensions
🍻 Homebrew tap for PHP extensions
Stars: ✭ 264 (+576.92%)
Mutual labels:  memcached
webuntis
A API library that makes it easy to access the Webuntis JSON RPC 2.0 API
Stars: ✭ 22 (-43.59%)
Mutual labels:  memcached
pytest-aiohttp
pytest plugin for aiohttp support
Stars: ✭ 110 (+182.05%)
Mutual labels:  aiohttp
go-elasticache
Thin abstraction over the Memcache client package gomemcache (https://github.com/bradfitz/gomemcache) allowing it to support AWS ElastiCache cluster nodes
Stars: ✭ 15 (-61.54%)
Mutual labels:  memcached
aioneo4j
asyncio client for neo4j
Stars: ✭ 29 (-25.64%)
Mutual labels:  aiohttp
quitsies
A persisted drop-in replacement for Memcached, respecting the rules of quitsies.
Stars: ✭ 16 (-58.97%)
Mutual labels:  memcached
python-logi-circle
Python 3.6+ API for Logi Circle cameras
Stars: ✭ 23 (-41.03%)
Mutual labels:  aiohttp
DEEPaaS
A REST API to serve machine learning and deep learning models
Stars: ✭ 26 (-33.33%)
Mutual labels:  aiohttp
kdk memcached object cache
Object cache driver for Memcached in WordPress (based on Memcached Redux)
Stars: ✭ 20 (-48.72%)
Mutual labels:  memcached
Pyro-FileStreamBot
Stream Telegram files to web
Stars: ✭ 38 (-2.56%)
Mutual labels:  aiohttp
tomodachi
💻 Microservice library / framework using Python's asyncio event loop with full support for HTTP + WebSockets, AWS SNS+SQS, RabbitMQ / AMQP, middleware, etc. Extendable for GraphQL, protobuf, gRPC, among other technologies.
Stars: ✭ 170 (+335.9%)
Mutual labels:  aiohttp
yutto
🧊 一个可爱且任性的 B 站视频下载器(bilili V2)
Stars: ✭ 383 (+882.05%)
Mutual labels:  aiohttp
netunnel
A tool to create network tunnels over HTTP/S written in Python 3
Stars: ✭ 19 (-51.28%)
Mutual labels:  aiohttp
trellio
Python3 asyncio based microframework for microservice architecture
Stars: ✭ 19 (-51.28%)
Mutual labels:  aiohttp
limits
Rate limiting using various strategies and storage backends such as redis & memcached
Stars: ✭ 178 (+356.41%)
Mutual labels:  memcached
Session
PHP Session Manager (non-blocking, flash, segment, session encryption)
Stars: ✭ 23 (-41.03%)
Mutual labels:  memcached
memcacher
C++ implementation of Memcache Binary Protocol.
Stars: ✭ 16 (-58.97%)
Mutual labels:  memcached
aiohttp-swagger3
Library for swagger documentation browsing and validating aiohttp requests using swagger specification 3.0
Stars: ✭ 54 (+38.46%)
Mutual labels:  aiohttp

Aiohttp-cache

aiohttp-cache logo

What's aiohttp-cache

aiohttp-cache is a plugin for aiohttp.web server that allow to use a cache system to improve the performance of your site.

How to use it

With in-memory backend

import asyncio

from aiohttp import web

from aiohttp_cache import (  # noqa
    setup_cache,
    cache,
)

PAYLOAD = {"hello": "aiohttp_cache"}
WAIT_TIME = 2


@cache()
async def some_long_running_view(
    request: web.Request,
) -> web.Response:
    await asyncio.sleep(WAIT_TIME)
    payload = await request.json()
    return web.json_response(payload)


app = web.Application()
setup_cache(app)
app.router.add_post("/", some_long_running_view)

web.run_app(app)

With redis backend

Note: redis should be available at $CACHE_URL env variable orredis://localhost:6379/0

import asyncio

import yarl
from aiohttp import web
from envparse import env

from aiohttp_cache import (  # noqa
    setup_cache,
    cache,
    RedisConfig,
)

PAYLOAD = {"hello": "aiohttp_cache"}
WAIT_TIME = 2


@cache()
async def some_long_running_view(
    request: web.Request,
) -> web.Response:
    await asyncio.sleep(WAIT_TIME)
    payload = await request.json()
    return web.json_response(payload)


app = web.Application()
url = yarl.URL(
    env.str("CACHE_URL", default="redis://localhost:6379/0")
)
setup_cache(
    app,
    cache_type="redis",
    backend_config=RedisConfig(
        db=int(url.path[1:]), host=url.host, port=url.port
    ),
)

app.router.add_post("/", some_long_running_view)

web.run_app(app)

Example with a custom cache key

Let's say you would like to cache the requests just by the method and json payload, then you can setup this as per the follwing example.

Note default key_pattern is:

DEFAULT_KEY_PATTERN = (
    AvailableKeys.method,
    AvailableKeys.host,
    AvailableKeys.path,
    AvailableKeys.postdata,
    AvailableKeys.ctype,
)
import asyncio

from aiohttp import web

from aiohttp_cache import (
    setup_cache,
    cache,
    AvailableKeys,
)  # noqa

PAYLOAD = {"hello": "aiohttp_cache"}
WAIT_TIME = 2


@cache()
async def some_long_running_view(
    request: web.Request,
) -> web.Response:
    await asyncio.sleep(WAIT_TIME)
    payload = await request.json()
    return web.json_response(payload)


custom_cache_key = (AvailableKeys.method, AvailableKeys.json)

app = web.Application()
setup_cache(app, key_pattern=custom_cache_key)
app.router.add_post("/", some_long_running_view)

web.run_app(app)

Parametrize the cache decorator

import asyncio

from aiohttp import web

from aiohttp_cache import (  # noqa
    setup_cache,
    cache,
)

PAYLOAD = {"hello": "aiohttp_cache"}
WAIT_TIME = 2


@cache(
    expires=1 * 24 * 3600,  # in seconds
    unless=False,  # anything what returns a bool. if True - skips cache
)
async def some_long_running_view(
    request: web.Request,
) -> web.Response:
    await asyncio.sleep(WAIT_TIME)
    payload = await request.json()
    return web.json_response(payload)


app = web.Application()
setup_cache(app)
app.router.add_post("/", some_long_running_view)

web.run_app(app)

License

This project is released under BSD license. Feel free

Source Code

The latest developer version is available in a github repository: https://github.com/cr0hn/aiohttp-cache

Development environment

  1. docker-compose run tests
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].