Add ability to clear cache and individual keys and new policy that allows cache size management in MB #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 useclearMemoryCache()
- only clears memory cacheclearCache()
- clears memory cache and deletes disk filesremoveCachedVideo(url)
- removes a single url from memory and diskAdded 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 toonEvict
so if multiple video streams were running at once, it didn't attempt to do evictions at the same time.Type of Change
Checklist
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.