mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-24 20:47:54 +00:00
first commit
This commit is contained in:
19
fastapi_cache/backends/mencache.py
Normal file
19
fastapi_cache/backends/mencache.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from typing import Tuple
|
||||
|
||||
from aiomcache import Client
|
||||
|
||||
from fastapi_cache.backends import Backend
|
||||
|
||||
|
||||
class MemcacheBackend(Backend):
|
||||
def __init__(self, mcache: Client):
|
||||
self.mcache = mcache
|
||||
|
||||
async def get_with_ttl(self, key: str) -> Tuple[int, str]:
|
||||
return 0, await self.mcache.get(key.encode())
|
||||
|
||||
async def get(self, key: str):
|
||||
return await self.mcache.get(key, key.encode())
|
||||
|
||||
async def set(self, key: str, value: str, expire: int = None):
|
||||
return await self.mcache.set(key.encode(), value.encode(), exptime=expire)
|
||||
Reference in New Issue
Block a user