Fix config file caching
This commit is contained in:
parent
b432503ac9
commit
691f9181e1
@ -10,7 +10,7 @@ import recurring_ical_events
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from asyncache import cached
|
from asyncache import cached
|
||||||
from cachetools import TTLCache, LRUCache
|
from cachetools import TTLCache, FIFOCache
|
||||||
from icalendar import Calendar
|
from icalendar import Calendar
|
||||||
|
|
||||||
from fabcal.models import CalendarEvent
|
from fabcal.models import CalendarEvent
|
||||||
@ -35,20 +35,23 @@ class CalendarClient:
|
|||||||
|
|
||||||
|
|
||||||
# this will be cached permanently, i.e., the server process needs to be restarted to apply config changes
|
# this will be cached permanently, i.e., the server process needs to be restarted to apply config changes
|
||||||
@cached(LRUCache(100))
|
# note that caching doesn't work at all with iterators (for obvious reasons)
|
||||||
def read_calendars_from_config_file():
|
@cached(FIFOCache(1))
|
||||||
|
def read_calendars_from_config_file() -> List[ConfiguredCalendar]:
|
||||||
|
rv = []
|
||||||
|
|
||||||
with open("config.yml") as f:
|
with open("config.yml") as f:
|
||||||
data = yaml.safe_load(f)
|
data = yaml.safe_load(f)
|
||||||
|
|
||||||
for calendar in data["calendars"]:
|
for calendar in data["calendars"]:
|
||||||
yield ConfiguredCalendar(**calendar)
|
rv.append(ConfiguredCalendar(**calendar))
|
||||||
|
|
||||||
|
return rv
|
||||||
|
|
||||||
|
|
||||||
class CombinedCalendarClient:
|
class CombinedCalendarClient:
|
||||||
def __init__(self, configured_calendars: List[ConfiguredCalendar]):
|
def __init__(self, configured_calendars: List[ConfiguredCalendar]):
|
||||||
# make sure it's a list since read_calendars_from_config_file() returns an iterator
|
self.configured_calendars = configured_calendars
|
||||||
self.configured_calendars = list(configured_calendars)
|
|
||||||
|
|
||||||
async def fetch_calendars(self) -> Dict[ConfiguredCalendar, str]:
|
async def fetch_calendars(self) -> Dict[ConfiguredCalendar, str]:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
|
Loading…
Reference in New Issue
Block a user