Skip to content

Commit 0ae1de0

Browse files
committed
Handle more scenarios in delete_cache() methods
Properly recreates tables if the file had to be deleted
1 parent f2ffa26 commit 0ae1de0

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

resources/arts.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,14 @@ def delete_cache():
9898
"""
9999
Deletes the cache containing the data about which art types are available or not
100100
"""
101-
os.remove(ART_AVAILABILITY_CACHE_FILE + ".sqlite")
101+
# If Kodi's request-cache module is updated to >0.7.3 , we will only need to issue cached_requests.cache.clear() which will handle all scenarios. Until then, we must recreate the backend ourselves
102+
try:
103+
cached_requests.cache.clear()
104+
except Exception:
105+
log('Failed to clear cache. Attempting manual deletion')
106+
try:
107+
os.remove(ART_AVAILABILITY_CACHE_FILE + ".sqlite")
108+
except:
109+
log('Failed to delete cache file')
110+
cached_requests.cache.responses = requests_cache.backends.storage.dbdict.DbPickleDict(ART_AVAILABILITY_CACHE_FILE + ".sqlite", 'responses', fast_save=True)
111+
cached_requests.cache.keys_map = requests_cache.backends.storage.dbdict.DbDict(ART_AVAILABILITY_CACHE_FILE + ".sqlite", 'urls')

resources/steam.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
STEAM_GAMES_CACHE_FILE = xbmc.translatePath(os.path.join(addonUserDataFolder, 'requests_cache_games'))
2121

2222
# cache expires after: 86400=1 day 604800=7 days
23-
cached_requests = requests_cache.core.CachedSession(STEAM_GAMES_CACHE_FILE, backend='sqlite',
23+
cached_requests = requests_cache.CachedSession(STEAM_GAMES_CACHE_FILE, backend='sqlite',
2424
expire_after=60 * minutesBeforeGamesListsExpiration,
2525
old_data_on_error=True)
2626

@@ -106,4 +106,18 @@ def get_user_games(steam_api_key, steam_user_id, recent_only=False):
106106

107107

108108
def delete_cache():
109-
os.remove(STEAM_GAMES_CACHE_FILE + ".sqlite")
109+
"""
110+
Deletes the cache containing the data about which games are owned or not
111+
"""
112+
# If Kodi's request-cache module is updated to >0.7.3 , we will only need to issue cached_requests.cache.clear() which will handle all scenarios. Until then, we must recreate the backend ourselves
113+
try:
114+
cached_requests.cache.clear()
115+
except Exception:
116+
log('Failed to clear cache. Attempting manual deletion')
117+
try:
118+
os.remove(STEAM_GAMES_CACHE_FILE + ".sqlite")
119+
except:
120+
log('Failed to delete & recreate cache')
121+
cached_requests.cache.responses = requests_cache.backends.storage.dbdict.DbPickleDict(STEAM_GAMES_CACHE_FILE + ".sqlite", 'responses', fast_save=True)
122+
cached_requests.cache.keys_map = requests_cache.backends.storage.dbdict.DbDict(STEAM_GAMES_CACHE_FILE + ".sqlite", 'urls')
123+

0 commit comments

Comments
 (0)