forked from facundoolano/google-play-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (52 loc) · 1.81 KB
/
index.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
'use strict';
const R = require('ramda');
const constants = require('./lib/constants');
const memoizee = require('memoizee');
const getParseList = require('./lib/utils/parseList');
const appMethod = require('./lib/app');
const parseList = R.partial(getParseList, [appMethod]);
const methods = {
app: appMethod,
list: require('./lib/list'),
search: R.partial(require('./lib/search'), [parseList, appMethod]),
suggest: require('./lib/suggest'),
developer: require('./lib/developer'),
reviews: require('./lib/reviews'),
similar: require('./lib/similar'),
permissions: require('./lib/permissions'),
categories: require('./lib/categories'),
homeCategories: require('./lib/homeCategories'),
liveOps: require('./lib/liveOps'),
};
function memoized (opts) {
const cacheOpts = Object.assign(
{
primitive: true,
normalizer: JSON.stringify,
maxAge: 1000 * 60 * 5, // cache for 5 minutes
max: 1000 // save up to 1k results to avoid memory issues
},
opts
);
// need to rebuild the methods so they all share the same memoized appMethod
const doMemoize = fn => memoizee(fn, cacheOpts);
const mAppMethod = memoizee(appMethod, cacheOpts);
const otherMethods = {
list: require('./lib/list'),
search: R.partial(require('./lib/search'), [parseList, appMethod]),
suggest: require('./lib/suggest'),
developer: require('./lib/developer'),
reviews: require('./lib/reviews'),
similar: require('./lib/similar'),
permissions: require('./lib/permissions'),
categories: require('./lib/categories'),
homeCategories: require('./lib/homeCategories'),
liveOps: require('./lib/liveOps'),
};
return Object.assign(
{ app: mAppMethod },
constants,
R.map(doMemoize, otherMethods)
);
}
module.exports = Object.assign({ memoized }, constants, methods);