Skip to content

Add ability to clear cache and individual keys and new policy that allows cache size management in MB #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

phazei
Copy link

@phazei phazei commented Jan 24, 2025

Pull Request

Description

Fixed some misc build issues, some still remain.

Added fixes for cases where there were stale cache keys. If something didn't exist in the filesystem and the key existed, it was just broken. Now it checks to make sure the file exists, if not it clears the key from memoryCache and that also clears the key from cachePolicy.

Added new ProxyCacheManager methods:
get memoryCache() - returns memoryCache for user use
clearMemoryCache() - only clears memory cache
clearCache() - clears memory cache and deletes disk files
removeCachedVideo(url) - removes a single url from memory and disk

Added to useAsyncCache:
removeVideoFromCache(url) to access from a component where the url may have been set. If anything happens to get corrupted this makes it possible to delete the cache and start over, previously it was just permanently broken.

Fixed some cases in LFUPolicy where onEvict could fail if they all had equal frequency, now it falls back to first cache entry entered.

Added a new CachePolicy: LFUSizePolicy
This works similarly to LFUPolicy, but when initializing it, the number is the size in MB for the cache. Now you can control how big the cache will get. It will grab a file list and delete the least frequented ones, falling back to the file with the oldest timestamp if that doesn't work. Additionally had to add more calls to onEvict since it wasn't ever called after first adding the files when they were small since they hadn't streamed much yet. Now it's also called on memoryCache get in addition to the put, extra calls shouldn't matter for other policies. Additionally, added an isEvicting check to onEvict so if multiple video streams were running at once, it didn't attempt to do evictions at the same time.

Type of Change

  • Bug Fix
  • New Feature
  • Enhancement
  • Documentation Update
  • Other (please specify)

Checklist

  • I have read the contribution guidelines and followed the process.
  • My code follows the coding standards of this project.
  • I have added unit tests for my changes/ I have integrate in example project.
  • I have updated the documentation accordingly.
  • The code builds and passes all existing tests locally.

The example project doesn't build, it's too old and hasn't been updated in too long. eslint and other checks and ts builds just fine. I added as many tests as already existed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant