Skip to main content

Decorator to cache in Deta base

Project description

DetaCache

Async and Sync Function Decorator to cache function call's to Deta base.

Installing

pip3 install DetaCache

Async and Sync Decorator to cache function

import asyncio
import aiohttp
import requests

from DetaCache import detaCache

app = detaCache('projectKey')

@app.cacheAsyncFunction()
async def asyncgetjSON(url:str):
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as response:
            return await response.json()

@app.cacheSyncFunction()
def syncgetjSON(url:str):
    return requests.get(url).json()

async def main():
    asyncdata = await asyncgetjSON('https://httpbin.org/json')
    print(asyncdata)
    syncdata = syncgetjSON('https://httpbin.org/json')
    print(syncdata)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

License

MIT License

Copyright (c) 2021 Vidya Sagar

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

DetaCache-0.0.4.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

DetaCache-0.0.4-py3-none-any.whl (6.5 kB view hashes)

Uploaded Python 3

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