Skip to content

Commit 236164c

Browse files
Hao PhanHao Phan
authored andcommitted
add new method: "setCacheResponseTime"
1 parent a350f87 commit 236164c

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ term **add**
108108
client.setPostfixWildcard(false);
109109
```
110110

111+
112+
#### Set enableLogicalOperators
113+
```js
114+
// (default: false)
115+
// enableLogicalOperators(true) = Support user specified logical operators (and/or/not) in the search query like "cat and dog"
116+
// enableLogicalOperators(false) = Treat logical operators in the search query as literal strings
117+
client.enableLogicalOperators(true);
118+
```
119+
120+
#### Set cacheResponseTime
121+
Caching the response, define the time-to-live of the cache.
122+
123+
```js
124+
// Specify time-to-live value in milliseconds
125+
client.setCacheResponseTime(3600);
126+
```
127+
128+
111129
### Pagination
112130
Set page number, page size and sorting parameters. It's possible to order results by:
113131
- relevance (descending)
@@ -197,13 +215,6 @@ client.setFilterObject(filter);
197215
client.setResultType('organic');
198216
```
199217

200-
#### Set enableLogicalOperators
201-
```js
202-
// (default: false)
203-
// enableLogicalOperators(true) = Support user specified logical operators (and/or/not) in the search query like "cat and dog"
204-
// enableLogicalOperators(false) = Treat logical operators in the search query as literal strings
205-
client.enableLogicalOperators(true);
206-
```
207218

208219
### Facets
209220
```js

dist/addsearch-js-client.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/apifetch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
8080
settingToQueryParam(settings.jwt, 'jwt') +
8181
settingToQueryParam(settings.resultType, 'resultType') +
8282
settingToQueryParam(settings.userToken, 'userToken') +
83-
settingToQueryParam(settings.numFacets, 'numFacets');
83+
settingToQueryParam(settings.numFacets, 'numFacets') +
84+
settingToQueryParam(settings.cacheResponseTime, 'cacheResponseWithTtlSeconds');
8485

8586
// Add custom field filters
8687
if (settings.customFieldFilters) {

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ var client = function(sitekey, privatekey) {
155155
this.setShuffleAndLimitTo = function(shuffleAndLimitTo) { this.settings.setShuffleAndLimitTo(shuffleAndLimitTo); }
156156
this.setFuzzyMatch = function(fuzzy) { this.settings.setFuzzyMatch(fuzzy); }
157157
this.setPostfixWildcard = function(wildcard) { this.settings.setPostfixWildcard(wildcard); }
158+
this.setCacheResponseTime = function(cacheResponseTime) { this.settings.setCacheResponseTime(cacheResponseTime) }
158159
this.setCollectAnalytics = function(collectAnalytics) { this.settings.setCollectAnalytics(collectAnalytics); }
159160
this.setThrottleTime = function(delay) { API_THROTTLE_TIME_MS = delay; }
160161
this.setStatsSessionId = function(id) { this.sessionId = id; }

src/settings.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var settings = function() {
1818
autocomplete: {
1919
size: 10
2020
},
21-
enableLogicalOperators: false
21+
enableLogicalOperators: false,
22+
cacheResponseTime: null
2223
};
2324

2425
this.getSettings = function() {
@@ -68,6 +69,10 @@ var settings = function() {
6869
this.settings.enableLogicalOperators = enableLogicalOperators;
6970
}
7071

72+
this.setCacheResponseTime = function(cacheResponseTime) {
73+
this.settings.cacheResponseTime = cacheResponseTime;
74+
}
75+
7176
this.setPostfixWildcard = function(wildcard) {
7277
this.settings.postfixWildcard = wildcard;
7378
}

0 commit comments

Comments
 (0)