Async and Sync Function Decorator to cache function call's to 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.cache(expire=30)
async def asyncgetjSON(url:str):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
return await response.json()
@app.cache(expire=30)
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
Release history Release notifications | RSS feed
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.1.0.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for detacache-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d1ed67e479915f89d0709aca1ad0dd7c745aabe5e0cbb61e6f4a60d8e7a6ff3 |
|
MD5 | 4fd673bfabff0faa0c82cc4201c06b97 |
|
BLAKE2b-256 | 6eb10570522992cca251e64837d504feff88304223a618c5b336236b5dcb2539 |