-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathexample.js
62 lines (54 loc) · 1.63 KB
/
example.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var imageCache = require('./image-cache');
var path = require('path');
imageCache.setOptions({
dir: path.join(__dirname, 'cache/'),
compressed: false
});
var images = [
"https://4.bp.blogspot.com/-QcLPmwZh-VI/WU5rEVtx9WI/AAAAAAAAfWo/Rs9IBKIuqbc94LlWVjoXNSM_HN-6dQpdgCLcBGAs/s400/%255BHorribleSubs%255D%2BYu-Gi-Oh%2521%2BVRAINS%2B-%2B07%2B720p-muxed_001_1409.png",
"https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&url=https://lh3.googleusercontent.com/-AUpXPK4IOi4/AAAAAAAAAAI/AAAAAAAAAAA/AI6yGXxcuACwUIVtH8VfdOlCD8KQjDDZSw/s32-c-mo/photo.jpg"
];
var image = "https://4.bp.blogspot.com/-QcLPmwZh-VI/WU5rEVtx9WI/AAAAAAAAfWo/Rs9IBKIuqbc94LlWVjoXNSM_HN-6dQpdgCLcBGAs/s400/%255BHorribleSubs%255D%2BYu-Gi-Oh%2521%2BVRAINS%2B-%2B07%2B720p-muxed_001_1409.png";
// Async
imageCache.isCached(image, function(exists) {
if (exists) {
imageCache.getCache(image, function(error, result) {
console.log(result.hashFile);
});
} else {
imageCache.setCache(image, function(error) {
if (error) {
console.log(error);
} else {
console.log("cache ok");
}
});
}
});
imageCache.fetchImage(image).then((results) => {
console.log(results);
});
imageCache.flushCache(function(error, results) {
if (error) {
console.log(error);
} else {
console.log(results);
}
});
// Sync
var isCached = imageCache.isCachedSync(image);
if (isCached) {
let imageData = imageCache.getCacheSync(image);
console.log(imageData.url);
} else {
imageCache.setCache(image, function(error) {
if (!error) {
console.log("cache complete");
}
});
}
try {
imageCache.flushCacheSync();
} catch(error) {
console.log(error);
}