Skip to content

Commit 356d44e

Browse files
authored
Merge pull request #18 from AddSearch/new-setting-to-cache-response
add new method: "setCacheResponseTime"
2 parents 286f475 + 48098d6 commit 356d44e

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
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 seconds
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

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
@@ -154,6 +154,7 @@ var client = function(sitekey, privatekey) {
154154
this.setShuffleAndLimitTo = function(shuffleAndLimitTo) { this.settings.setShuffleAndLimitTo(shuffleAndLimitTo); }
155155
this.setFuzzyMatch = function(fuzzy) { this.settings.setFuzzyMatch(fuzzy); }
156156
this.setPostfixWildcard = function(wildcard) { this.settings.setPostfixWildcard(wildcard); }
157+
this.setCacheResponseTime = function(cacheResponseTime) { this.settings.setCacheResponseTime(cacheResponseTime) }
157158
this.setCollectAnalytics = function(collectAnalytics) { this.settings.setCollectAnalytics(collectAnalytics); }
158159
this.setThrottleTime = function(delay) { this.settings.setThrottleTime(delay); }
159160
this.setStatsSessionId = function(id) { this.sessionId = id; }

src/settings.js

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

2526
this.getSettings = function() {
@@ -73,6 +74,10 @@ var settings = function() {
7374
this.settings.enableLogicalOperators = enableLogicalOperators;
7475
}
7576

77+
this.setCacheResponseTime = function(cacheResponseTime) {
78+
this.settings.cacheResponseTime = cacheResponseTime;
79+
}
80+
7681
this.setPostfixWildcard = function(wildcard) {
7782
this.settings.postfixWildcard = wildcard;
7883
}

0 commit comments

Comments
 (0)