ZeroIntensity / view.py

The Batteries-Detachable Web Framework
https://view.zintensity.dev
MIT License
206 stars 15 forks source link

Stabilizing Caching #96

Closed ZeroIntensity closed 5 months ago

ZeroIntensity commented 7 months ago

Feature description

Caching was implemented very early in view.py, but was never really standardized. I think a cache function exists somewhere, but it's not at all tested. Ideally, this should be pretty easy to do, but there's probably a bug somewhere that causes it to segfault. If this does go well, perhaps caching could be enabled by default (or enabled by configuration).

Perhaps when #10 is done this could be integrated with Redis.

Feature example API

from view import new_app

app = new_app()

@app.get("/", cache_rate=10)
async def index():
    something = await some_heavy_operation()
    return something

app.run()

OR

from view import new_app, cache

app = new_app()

@app.get("/")
@cache(10)
async def index():
    something = await some_heavy_operation()
    return something

app.run()

Anything else?

No response