Skip to content

Commit 9469244

Browse files
committed
add example for providing own FileNameGenerator
1 parent 3023e4a commit 9469244

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [Recipes](#recipes)
99
- [Disk cache limit](#disk-cache-limit)
1010
- [Listen caching progress](#listen-caching-progress)
11+
- [Providing names for cached files](#providing-names-for-cached-files)
1112
- [Sample](#sample)
1213
- [Known problems](#known-problems)
1314
- [Whats new](#whats-new)
@@ -105,6 +106,26 @@ Use `HttpProxyCacheServer.isCached(String url)` method to check was url's conten
105106

106107
See `sample` app for more details.
107108

109+
### Providing names for cached files
110+
By default `AndroidVideoCache` uses MD5 of video url as file name. But in some cases url is not stable and it can contain some generated parts (e.g. session token). In this case caching mechanism will be broken. To fix it you have to provide own `FileNameGenerator`:
111+
``` java
112+
public class MyFileNameGenerator implements FileNameGenerator {
113+
114+
// Urls contain mutable parts (parameter 'sessionToken') and stable video's id (parameter 'videoId').
115+
// e. g. http://example.com?videoId=abcqaz&sessionToken=xyz987
116+
public String generate(String url) {
117+
Uri uri = Uri.parse(url);
118+
String videoId = uri.getQueryParameter("videoId");
119+
return videoId + ".mp4";
120+
}
121+
}
122+
123+
...
124+
HttpProxyCacheServer proxy = HttpProxyCacheServer.Builder(context)
125+
.fileNameGenerator(new MyFileNameGenerator())
126+
.build()
127+
```
128+
108129
### Sample
109130
See `sample` app.
110131

0 commit comments

Comments
 (0)