raix:cached-files

v0.0.2Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

raix:cache-files

This package will try to cache files for offline usage.

Usage

1    // These files should be loaded when the app is used the first time
2    // if the user wants to use a file not in the list CachedFile will
3    // pause a bit allowing the user to stream the specific file.
4    // CachedFile will add the file to the cache and continue loading the
5    // rest of the files.
6    CachedFile.install([
7        'http://gi2.dk/images/logo51x51.png',
8        'http://gi2.dk/media/1004/irish-hands.jpg'
9    ]);
10
11    CachedFile.quotas({
12        size: 1024, // size limit in bytes, 0 is disabled
13        count: 12,  // total number of files allowed, 0 disabled
14    });
15
16    // The CachedFile will adapt to the quota set, its done by weight /
17    // importance. To customize the behaviour one can change the values.
18    // Setting one to 0 will disable the weight. Negative values are allowed
19    // these will reverse the effect.
20    CachedFile.weight({
21        age: 1,
22        lastUsed: 1,
23        count: 1,
24        size: 1
25    });
26
27    // Add files to the cache later
28    CachedFile.add('http://gi2.dk/media/1001/fremhaevetgrafik_android_banner.png');
29
30    // Remove a file manually
31    CachedFile.remove('http://gi2.dk/media/1001/fremhaevetgrafik_android_banner.png');
1    {{#each CachedFile}}
2        {{#if isCached}}
3            <img src="{{url}}"/>
4        {{else}}
5            <img src="waiting.gif"/>
6        {{/if}}
7        <br/>
8    {{else}}
9        No files in cache
10    {{/each}}
11
12    <!-- Or -->
13
14    {{#with CachedFile 'http://gi2.dk/images/logo51x51.png'}}
15        {{#if isCached}}
16            <img src="{{url}}"/>
17        {{else}}
18            <img src="waiting.gif"/>
19        {{/if}}
20    {{/with}}
21