Does anyone have a way to automatically move the X number of most commonly used files back to the cache?


relink

Recommended Posts

So, I have 2 kids, and for any of you who also have kids you know they watch many of the same things on repeat all day. So instead of having to keep disks spinning, I was thinking to just move their favorite movies to the cache. This would actually keep all my disks from spinning for a large portion of the day. 

 

But of course, I don't want to just do it manually, thats not any fun. So I wanted to see if there was any way to see what the top 10 most watched movies and maybe shows are in plex and move them to and keep them in cache, and if the favorites change over time it will automatically move the less watched back to the Array and pull in the new most watched. 

figured it would be something fun to try a write a userscript for. Any thoughts? I doubt Im the only person to want to try something similar.

Link to comment

I wonder if you could modify this to target your specific movies and cache them into ram for those repeat performances. 

 

 

Sure its designed to cache the beginning of TV/Movies to allow you to start watching while the drive spins up and catches up, but that would be something @mgutt would be the expert at. ;) 

Link to comment
4 hours ago, relink said:

But of course, I don't want to just do it manually, thats not any fun. So I wanted to see if there was any way to see what the top 10 most watched movies and maybe shows are in plex and move them to and keep them in cache, and if the favorites change over time it will automatically move the less watched back to the Array and pull in the new most watched. 

I plan to realize a script which does this. The trick is to copy the files to the SSD, so they are on the Cache and the Array. By that the mover fails moving them back to the array. This should avoid spinning.

Link to comment

There is

/mnt/user0/Movies/ - No SSD

/mnt/user/Movies/ - Does Incorporate SSD

 

I'm sure you know that thou.

 

I tried at one time to come up with something of the sort myself, but honestly things started looking really complex tis why I thought storing them in RAM might be a decent idea and your script came to mind. Instead of it looking at the newest files maybe some targeted files would work. 

 

Could the script possibly be ran weekly proceeding the Mover and if the moved files does get moved have them moved back to the SSD? Otherwise I'd just recommend adding the targeted files to a Cache Only share and adding the share Path to Plex to the same library so they are included and never get moved. 

 

 

Link to comment
46 minutes ago, mgutt said:

I plan to realize a script which does this.

It would be awesome if you did, I actually already use your Plex preload script. I was analyzing it to see if I could reasonably tweak it, but it’s a bit over my head.
 

media files like movies, tv, and maybe music would be the top targets for something like this. A good chunk of my Plex usage is my kids watching the same shows and movies on repeat, but they also will randomly change it up for a few weeks to something else. If the script could cache the entire series of a show, that would be awesome too. I could literally go days without the array spinning up at all. 
 

and I love the idea of copying the data instead of moving it. That way if one of the SSDs were to fail you wouldn’t loose any data.

Link to comment

So I e been giving this some thought over night and I’d really like to take a stab at this. 
 

if all I need to do is make sure the file/directory exists on both the cache and the array, that’s easy enough to do. 
 

the tricky part is how do I find out when the file was last accessed? Considering the extra write required I doubt unRAID keeps track of “atime” on files. And I don’t know how to use the Plex API
 

but this could be made really simple I’m thinking. As an example If the movie has been watched in the last week copy its entire directory (so the srt files come too) to the cache. The script runs daily, and checks the last time a movie was watched, once it’s been more then 7days the copy gets deleted.

 

As for TV shows, I’m thinking it should copy entire seasons but this could be messy quick. Especially if - like me - you run something like DizqueTV. 

Link to comment
2 hours ago, relink said:

keeps track of “atime”

This could be a solution, but finally it could be a problem if something touches all files like a backup tool.

 

So it must be something which monitors dir X for process names Y or similar.

 

Or the Plex API. But this would work only for Plex.

 

I think Syno/QNAP has the same problem why they are killing the SSDs so fast.

Link to comment
  • 9 months later...

No unfortunately I still haven’t found a reliable way to do this automatically. And I opted to not do anything manual or janky that I’d end up forgetting I did a year from now. 
 

Honestly Im surprised this just isn’t a built in feature yet. A read cache seems like such an obvious thing to have.
 

I might consider taking a crack at it myself at some point but I have never used anything like inotify before. My scripting skills are mostly just from piecing together Google searches. Lol

Link to comment
  • 2 weeks later...
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.