forked from juanfe190/React-Native-Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CacheService.js
44 lines (35 loc) · 1.06 KB
/
CacheService.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import RNFS from 'react-native-fs';
import md5 from 'blueimp-md5';
import imageCache, {buildKeyHash} from './src/cache/imageCache';
import requestCache from './src/cache/requestCache';
import util from './src/cache/util';
export default
class Cache
{
/**
* Cacheo de imagenes
*
* @author Felix Vasquez, Baum Digital
*/
static async image(url, options = {})
{
let returning = null;
const filename = buildKeyHash(url);
let inCache = await util.checkCache(filename);
if(!inCache || options.forceUpdate) returning = await imageCache.createCache(url, options);
else returning = await imageCache.recoverCache(url, options);
return returning;
}
/**
* Cacheo de http request
*
* @author Felix Vasquez, Baum Digital
*/
static async request(url, params = {}, options)
{
const key = md5(url + JSON.stringify(params) + JSON.stringify(options));
let inCache = await util.checkCache(key);
if(!inCache || options.forceUpdate) return await requestCache.createCache(url, params, options);
return await requestCache.recoverCache(url, params, options);
}
}