Grocel / 3D-Stream-Radio

It is an spawnable scripted entity for Garry's Mod that allows you to play online streams and local files as 3D world sound.
https://steamcommunity.com/sharedfiles/filedetails/?id=246756300
17 stars 4 forks source link

Peekofwar: About the audio cache. #19

Closed Grocel closed 10 months ago

Grocel commented 11 months ago

@Peekofwar on Workshop:

Heck, I just discovered that there's an audio cache... I have some cached DAT files from 2018, and interestingly, Audacity allows me to just drag the DAT files right into it to view them.

https://github.com/Grocel/3D-Stream-Radio/blob/master/lua/streamradio_core/cache.lua#L17-L21

Yes, indeed. Files are downloaded in the background via HTTP() to make the loadup faster the next time the radio plays an online file. It reduces traffic and is a good Anti-DDoS/Anti-Spam too.

It only works with files with a length (e.g. not radio streams). Only files less then 1.5h long are cached. The cache is capped at 16 GB total size and 1024 files. Each file is limited to 256 MB. Small files (HTTP requests) are even cached in memory (max 16x16 MB) as an additional de-duplication of requests. Small files (<64 KB) that could just be an HTML error page or something are never cached. Caching is only attempted when the radio does not error on playback, which means only valid sound content ends up there.

You can clear the file cache any time by deleting the cache folder or by using "cl_streamradio_cacheclear" ingame. The dat files can be any sound file and are saved as dat because of engine restrictions.

Peekofwar commented 11 months ago

Theoretically you could have a function that runs on startup that checks for files that haven't been used for a long time (maybe like a year) and deletes them. Unless metadata is modified or something, there'd also have to be some kind of data file that keeps track of the last time each cached DAT file was used.

Or you could have a message that pops up that tells the player that they have old sounds in their Stream Radio cache with the command to clear it printed in chat.

Grocel commented 11 months ago

Keep in mind that the cache already deletes files, when it gets full. It never gets clogged. Cache can be cleared in the settings as well, the button is right there on the settings panel. No need for extra complexity or micro managing worthless cache data. However I can add logic to ensure that the files have a max life time of like a week each.

Peekofwar commented 11 months ago

Keep in mind that the cache already deletes files, when it gets full. It never gets clogged. Cache can be cleared in the settings as well, the button is right there on the settings panel. No need for extra complexity or micro managing worthless cache data. However I can add logic to ensure that the files have a max life time of like a week each.

Oh, didn't know it had a limit. Guess I just haven't streamed that many web files.

Grocel commented 10 months ago

Max age for cache files added with d902a7569c4eb960326c05aea8cc5a93583c5099. Along with other changes.