I am very confused with exoplayer and their documentation, They have explained everything in very short. Can anyone please tell me what exactly leastRecentlyUsedCacheEvictor is and how it work? use case and methods?
Asked
Active
Viewed 858 times
1 Answers
6
ExoPlayer video cache uses a CacheEvictor instance to tell the library when to delete cached files. LeastRecentlyUsedCacheEvictor
as the name represents declares that policy in a least recently used order.
Assuming you have watched video A, B, C, A (again) and D (order matters) and you hit the maximum cache capacity passed in LeastRecentlyUsedCacheEvictor
constructor. The evictor instance lists the cache usages and finds video B as the least recently used one and deletes it to free space.
Here is a simple usage example:
public class VideoCacheSingleton {
private static final int MAX_VIDEO_CACHE_SIZE_IN_BYTES = 200 * 1024 * 1024; // 200MB
private static Cache sInstance;
public static Cache getInstance(Context context) {
if (sInstance != null) return sInstance;
else return sInstance = new SimpleCache(new File(context.getCacheDir(), "video"), new LeastRecentlyUsedCacheEvictor(MAX_VIDEO_CACHE_SIZE_IN_BYTES), new ExoDatabaseProvider(context)));
}
}

Sdghasemi
- 5,370
- 1
- 34
- 42
-
if i am using LeastRecentlyUsedCacheEvictor in exoplayer with multiple playerView then should i create singleton of this? – nirazverma Sep 14 '20 at 09:43
-
`CacheEvictor`s are used to build ExoPlayer cache instances. The library prevents using multiple cache instances to access a same folder. Hence you should use singleton classes for every cache folder you declare. – Sdghasemi Sep 14 '20 at 10:03
-
https://stackoverflow.com/questions/63883690/cachedatasource-vs-simplecache-in-exoplayer if you can answer please – nirazverma Sep 14 '20 at 11:49
-
https://stackoverflow.com/questions/64006634/how-to-create-single-instance-of-exoplayer-and-use-it-with-multiple-playerviews if you could help – nirazverma Sep 22 '20 at 11:29