Skip to content

Commit

Permalink
add example for providing own FileNameGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
danikula committed Dec 6, 2016
1 parent 3023e4a commit 9469244
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [Recipes](#recipes)
- [Disk cache limit](#disk-cache-limit)
- [Listen caching progress](#listen-caching-progress)
- [Providing names for cached files](#providing-names-for-cached-files)
- [Sample](#sample)
- [Known problems](#known-problems)
- [Whats new](#whats-new)
Expand Down Expand Up @@ -105,6 +106,26 @@ Use `HttpProxyCacheServer.isCached(String url)` method to check was url's conten

See `sample` app for more details.

### Providing names for cached files
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`:
``` java
public class MyFileNameGenerator implements FileNameGenerator {

// Urls contain mutable parts (parameter 'sessionToken') and stable video's id (parameter 'videoId').
// e. g. http://example.com?videoId=abcqaz&sessionToken=xyz987
public String generate(String url) {
Uri uri = Uri.parse(url);
String videoId = uri.getQueryParameter("videoId");
return videoId + ".mp4";
}
}

...
HttpProxyCacheServer proxy = HttpProxyCacheServer.Builder(context)
.fileNameGenerator(new MyFileNameGenerator())
.build()
```

### Sample
See `sample` app.

Expand Down

0 comments on commit 9469244

Please sign in to comment.