Skip to main content

Caching middleware for aiohttp server with aiocache under the hood

Project description

aiohttp-aiocache

Maintainability Test Coverage

Caching middleware for aiohttp server with aiocache under the hood. Inspired by aiohttp-cache.

Installation

pip install aiohttp-aiocache

or

poetry add aiohttp-aiocache

Optional aiocache dependencies for redis, memcached and msgpack support will not be installed. Install them manually if required.

Usage

import asyncio

import aiohttp.web as web
from aiocache import Cache
from aiocache.serializers import PickleSerializer

from aiohttp_aiocache import cached, register_cache


@cached  # mark handler with decorator
async def handler(_: web.Request) -> web.Response:
    await asyncio.sleep(1)
    return web.Response(text="Hello world")

app = web.Application()
app.router.add_route("GET", "/", handler)

# create aiocache instance
cache = Cache(
    Cache.MEMORY,
    serializer=PickleSerializer(),
    namespace="main",
    ttl=60,
)

# register cache backend in appplication
register_cache(app, cache)

web.run_app(app)

Limitations

Support caching for GET requests only.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp-aiocache-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

aiohttp_aiocache-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp-aiocache-0.1.0.tar.gz.

File metadata

  • Download URL: aiohttp-aiocache-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.7.5 Linux/5.0.0-1027-azure

File hashes

Hashes for aiohttp-aiocache-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4ff4bb4badf5af184f6f438b534356395684a121650ae9e18e2901d300fd6270
MD5 c710ac6dd00e4037c04d851d085c8384
BLAKE2b-256 5c666e0ce9b8a34209c07839e2166adab9b015044e5ff556aa20448a66fd87ee

See more details on using hashes here.

File details

Details for the file aiohttp_aiocache-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aiohttp_aiocache-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.7.5 Linux/5.0.0-1027-azure

File hashes

Hashes for aiohttp_aiocache-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ebcf2877b16858bdbddf7d921263fae3818a06b0800fff2bdae8a09f69a847d
MD5 4b5fe6f2bb6e249516fa8adb68a2d7ac
BLAKE2b-256 cc54333a5764125e91f75dcc9f54339d8014329ad7cd990cb4f466f5a920e8f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page