store new cache results to both sqlite and redis, in that order
This commit is contained in:
@@ -96,11 +96,24 @@ class Cache:
|
||||
|
||||
async def store(self, lyr_result: LyricsResult) -> None:
|
||||
"""
|
||||
Store lyrics to cache
|
||||
Store lyrics (SQLite, then Redis)
|
||||
Args:
|
||||
lyr_result: the returned lyrics to cache
|
||||
lyr_result (LyricsResult): the returned lyrics to cache
|
||||
Returns: None
|
||||
"""
|
||||
|
||||
sqlite_insert_id = await self.sqlite_store(lyr_result)
|
||||
if sqlite_insert_id:
|
||||
await self.redis_cache.redis_store(sqlite_insert_id, lyr_result)
|
||||
|
||||
|
||||
async def sqlite_store(self, lyr_result: LyricsResult) -> int:
|
||||
"""
|
||||
Store lyrics to SQLite Cache
|
||||
Args:
|
||||
lyr_result (LyricsResult): the returned lyrics to cache
|
||||
Returns:
|
||||
None
|
||||
int: the inserted row id
|
||||
"""
|
||||
|
||||
logging.info("Storing %s",
|
||||
@@ -129,10 +142,12 @@ class Cache:
|
||||
async with await db_conn.executescript(self.cache_pre_query) as _db_cursor:
|
||||
async with await db_conn.execute(insert_query, params) as _cursor:
|
||||
await db_conn.commit()
|
||||
logging.info("Stored %s!", artistsong.replace("\n", " - "))
|
||||
logging.info("Stored %s to SQLite!", artistsong.replace("\n", " - "))
|
||||
return _cursor.lastrowid
|
||||
except:
|
||||
logging.critical("Cache storage error!")
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
|
||||
Reference in New Issue
Block a user