16 lines
551 B
Python
16 lines
551 B
Python
from fastapi import APIRouter
|
|
import aiofiles
|
|
import json
|
|
from async_lru import alru_cache
|
|
|
|
router = APIRouter(prefix='/api/v1', tags=['tariffs'])
|
|
|
|
@alru_cache(maxsize=1, ttl=86400)
|
|
async def get_tariffs_from_file():
|
|
async with aiofiles.open('data/tariffs.json', 'r', encoding='utf-8') as f:
|
|
content = await f.read()
|
|
return json.loads(content) # <- блокирующая операция, но с маленьким контентом + кэш
|
|
|
|
@router.get('/tariffs')
|
|
async def get_tariffs():
|
|
return await get_tariffs_from_file() |