mirror of
https://github.com/jellyfin/jellycon.git
synced 2025-02-22 23:03:06 +00:00
auto delete cache items that have not been accessed for 7 days
This commit is contained in:
parent
59b018bf00
commit
350031a238
@ -28,9 +28,11 @@ class CacheItem:
|
|||||||
item_list = None
|
item_list = None
|
||||||
item_list_hash = None
|
item_list_hash = None
|
||||||
date_saved = None
|
date_saved = None
|
||||||
|
date_last_used = None
|
||||||
last_action = None
|
last_action = None
|
||||||
items_url = None
|
items_url = None
|
||||||
file_path = None
|
file_path = None
|
||||||
|
user_id = None
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
pass
|
pass
|
||||||
@ -96,7 +98,7 @@ class DataManager:
|
|||||||
item_list = cache_item.item_list
|
item_list = cache_item.item_list
|
||||||
total_records = cache_item.total_records
|
total_records = cache_item.total_records
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
log.debug("Pickle Data Load Failed : {0}", err)
|
log.error("Pickle Data Load Failed : {0}", err)
|
||||||
item_list = None
|
item_list = None
|
||||||
|
|
||||||
# we need to load the list item data form the server
|
# we need to load the list item data form the server
|
||||||
@ -128,8 +130,10 @@ class DataManager:
|
|||||||
cache_item.item_list = item_list
|
cache_item.item_list = item_list
|
||||||
cache_item.file_path = cache_file
|
cache_item.file_path = cache_file
|
||||||
cache_item.items_url = url
|
cache_item.items_url = url
|
||||||
|
cache_item.user_id = user_id
|
||||||
cache_item.last_action = "fresh_data"
|
cache_item.last_action = "fresh_data"
|
||||||
cache_item.date_saved = time.time()
|
cache_item.date_saved = time.time()
|
||||||
|
cache_item.date_last_used = time.time()
|
||||||
cache_item.total_records = total_records
|
cache_item.total_records = total_records
|
||||||
|
|
||||||
cache_thread.cached_item = cache_item
|
cache_thread.cached_item = cache_item
|
||||||
@ -178,6 +182,7 @@ class CacheManagerThread(threading.Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
log.debug("CacheManagerThread : Started")
|
log.debug("CacheManagerThread : Started")
|
||||||
|
# log.debug("CacheManagerThread : Cache Item : {0}", self.cached_item.__dict__)
|
||||||
|
|
||||||
home_window = HomeWindow()
|
home_window = HomeWindow()
|
||||||
is_fresh = False
|
is_fresh = False
|
||||||
@ -195,6 +200,7 @@ class CacheManagerThread(threading.Thread):
|
|||||||
self.cached_item.item_list_hash = cached_hash
|
self.cached_item.item_list_hash = cached_hash
|
||||||
self.cached_item.last_action = "cached_data"
|
self.cached_item.last_action = "cached_data"
|
||||||
self.cached_item.date_saved = time.time()
|
self.cached_item.date_saved = time.time()
|
||||||
|
self.cached_item.date_last_used = time.time()
|
||||||
|
|
||||||
loops = self.wait_for_save(home_window, self.cached_item.file_path)
|
loops = self.wait_for_save(home_window, self.cached_item.file_path)
|
||||||
|
|
||||||
@ -240,6 +246,7 @@ class CacheManagerThread(threading.Thread):
|
|||||||
self.cached_item.item_list_hash = loaded_hash
|
self.cached_item.item_list_hash = loaded_hash
|
||||||
self.cached_item.last_action = "fresh_data"
|
self.cached_item.last_action = "fresh_data"
|
||||||
self.cached_item.date_saved = time.time()
|
self.cached_item.date_saved = time.time()
|
||||||
|
self.cached_item.date_last_used = time.time()
|
||||||
self.cached_item.total_records = total_records
|
self.cached_item.total_records = total_records
|
||||||
|
|
||||||
# we need to refresh but will wait until the main function has finished
|
# we need to refresh but will wait until the main function has finished
|
||||||
@ -252,6 +259,14 @@ class CacheManagerThread(threading.Thread):
|
|||||||
log.debug("CacheManagerThread : Sending container refresh ({0})", loops)
|
log.debug("CacheManagerThread : Sending container refresh ({0})", loops)
|
||||||
xbmc.executebuiltin("Container.Refresh")
|
xbmc.executebuiltin("Container.Refresh")
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.cached_item.date_last_used = time.time()
|
||||||
|
loops = self.wait_for_save(home_window, self.cached_item.file_path)
|
||||||
|
with open(self.cached_item.file_path, 'wb') as handle:
|
||||||
|
cPickle.dump(self.cached_item, handle, protocol=cPickle.HIGHEST_PROTOCOL)
|
||||||
|
log.debug("CacheManagerThread : Updating last used date for cache data ({0})", loops)
|
||||||
|
home_window.clearProperty(self.cached_item.file_path)
|
||||||
|
|
||||||
log.debug("CacheManagerThread : Exited")
|
log.debug("CacheManagerThread : Exited")
|
||||||
|
|
||||||
|
|
||||||
@ -272,4 +287,30 @@ def clear_cached_server_data():
|
|||||||
xbmcgui.Dialog().ok(string_load(30393), msg)
|
xbmcgui.Dialog().ok(string_load(30393), msg)
|
||||||
|
|
||||||
|
|
||||||
|
def clear_old_cache_data():
|
||||||
|
log.debug("clear_old_cache_data() called")
|
||||||
|
|
||||||
|
addon_dir = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile'))
|
||||||
|
dirs, files = xbmcvfs.listdir(addon_dir)
|
||||||
|
|
||||||
|
del_count = 0
|
||||||
|
for filename in files:
|
||||||
|
if filename.startswith("cache_") and filename.endswith(".pickle"):
|
||||||
|
log.debug("Checking CacheFile: {0}", filename)
|
||||||
|
|
||||||
|
with open(os.path.join(addon_dir, filename), 'rb') as handle:
|
||||||
|
cache_item = cPickle.load(handle)
|
||||||
|
|
||||||
|
item_last_used = -1
|
||||||
|
if cache_item.date_last_used is not None:
|
||||||
|
item_last_used = time.time() - cache_item.date_last_used
|
||||||
|
|
||||||
|
log.debug("Cache item last used : {0} sec ago", item_last_used)
|
||||||
|
if item_last_used == -1 or item_last_used > (3600 * 24 * 7):
|
||||||
|
log.debug("Deleting cache item age : {0}", item_last_used)
|
||||||
|
xbmcvfs.delete(os.path.join(addon_dir, filename))
|
||||||
|
del_count += 1
|
||||||
|
|
||||||
|
log.debug("Cache items deleted : {0}", del_count)
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ from .resume_dialog import ResumeDialog
|
|||||||
from .utils import PlayUtils, getArt, id_generator, send_event_notification
|
from .utils import PlayUtils, getArt, id_generator, send_event_notification
|
||||||
from .kodi_utils import HomeWindow
|
from .kodi_utils import HomeWindow
|
||||||
from .translation import string_load
|
from .translation import string_load
|
||||||
from .datamanager import DataManager
|
from .datamanager import DataManager, clear_old_cache_data
|
||||||
from .item_functions import extract_item_info, add_gui_item
|
from .item_functions import extract_item_info, add_gui_item
|
||||||
from .clientinfo import ClientInformation
|
from .clientinfo import ClientInformation
|
||||||
from .functions import delete, markWatched, markUnwatched
|
from .functions import delete, markWatched, markUnwatched
|
||||||
@ -1092,6 +1092,8 @@ class PlaybackService(xbmc.Monitor):
|
|||||||
|
|
||||||
#xbmc.executebuiltin("Dialog.Close(selectdialog, true)")
|
#xbmc.executebuiltin("Dialog.Close(selectdialog, true)")
|
||||||
|
|
||||||
|
clear_old_cache_data()
|
||||||
|
|
||||||
cache_images = settings.getSetting('cacheImagesOnScreenSaver') == 'true'
|
cache_images = settings.getSetting('cacheImagesOnScreenSaver') == 'true'
|
||||||
if cache_images:
|
if cache_images:
|
||||||
self.background_image_cache_thread = CacheArtwork()
|
self.background_image_cache_thread = CacheArtwork()
|
||||||
|
@ -21,9 +21,12 @@ from resources.lib.menu_functions import set_library_window_values
|
|||||||
from resources.lib.context_monitor import ContextMonitor
|
from resources.lib.context_monitor import ContextMonitor
|
||||||
from resources.lib.server_detect import checkServer
|
from resources.lib.server_detect import checkServer
|
||||||
from resources.lib.library_change_monitor import LibraryChangeMonitor
|
from resources.lib.library_change_monitor import LibraryChangeMonitor
|
||||||
|
from resources.lib.datamanager import clear_old_cache_data
|
||||||
|
|
||||||
settings = xbmcaddon.Addon()
|
settings = xbmcaddon.Addon()
|
||||||
|
|
||||||
|
clear_old_cache_data()
|
||||||
|
|
||||||
# clear user and token when logging in
|
# clear user and token when logging in
|
||||||
home_window = HomeWindow()
|
home_window = HomeWindow()
|
||||||
home_window.clearProperty("userid")
|
home_window.clearProperty("userid")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user