From 2bc7c557db9e03e77df8c6eff07914d2b2f3d615 Mon Sep 17 00:00:00 2001 From: KubaPro010 <132459354+KubaPro010@users.noreply.github.com> Date: Thu, 6 Nov 2025 18:56:17 +0100 Subject: [PATCH] better cache --- modules/cache.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/cache.py b/modules/cache.py index af141d6..5399797 100644 --- a/modules/cache.py +++ b/modules/cache.py @@ -13,14 +13,14 @@ class Module(PlayerModule): next = self.playlist[index] else: next = self.playlist[index+1] + def prefetch(path): + with open(path, "rb") as f: + fd = f.fileno() + os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_SEQUENTIAL) + os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_NOREUSE) + os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_WILLNEED) - with open(track.path.absolute(), "rb") as f: - os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_SEQUENTIAL) - os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_NOREUSE) - os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_WILLNEED) - with open(next, "rb") as f: - os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_SEQUENTIAL) - os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_NOREUSE) - os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_WILLNEED) + prefetch(track.path.absolute()) + prefetch(next) module = Module() \ No newline at end of file