Skip to content

Commit e7a28e7

Browse files
author
James Vidler
authored
Merge pull request #64 from agility/remove-cache-adapter
removed cache adapter
2 parents b80c927 + 3ad980e commit e7a28e7

File tree

9 files changed

+15
-86
lines changed

9 files changed

+15
-86
lines changed

package-lock.json

Lines changed: 3 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@agility/content-fetch",
3-
"version": "1.0.3",
3+
"version": "1.1.0",
44
"description": "JavaScript library for the Agility Fetch API (node and browser)",
55
"main": "dist/agility-content-fetch.node.js",
66
"scripts": {
@@ -38,7 +38,6 @@
3838
"webpack-cli": "^3.2.3"
3939
},
4040
"dependencies": {
41-
"axios": "^0.21.1",
42-
"axios-cache-adapter": "^2.4.1"
41+
"axios": "^0.21.1"
4342
}
4443
}

src/api-client.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import axios from 'axios'
2-
import { setupCache } from 'axios-cache-adapter'
32
import getSitemapFlat from './methods/getSitemapFlat'
43
import getSitemapNested from './methods/getSitemapNested'
54
import getContentItem from './methods/getContentItem'
@@ -94,14 +93,6 @@ export default function createClient(userConfig) {
9493

9594
let adapter = null;
9695

97-
//should we turn on caching?
98-
if (config.caching.maxAge > 0) {
99-
const cache = setupCache({
100-
maxAge: config.caching.maxAge,
101-
exclude: { query: false }
102-
});
103-
adapter = cache.adapter;
104-
}
10596

10697
const https= require("https")
10798

@@ -112,14 +103,11 @@ export default function createClient(userConfig) {
112103
api = axios.create({
113104
httpsAgent: new https.Agent({
114105
rejectUnauthorized: false
115-
}),
116-
adapter: adapter,
106+
})
117107
})
118108
} else {
119109
//we can't use the https.Agent
120-
api = axios.create({
121-
adapter: adapter,
122-
})
110+
api = axios.create({})
123111
}
124112

125113

@@ -135,17 +123,12 @@ export default function createClient(userConfig) {
135123
return api(reqConfig).then(async (response) => {
136124

137125
let data = response.data;
138-
//if our response is from cache, inject that property in the data response
139-
if (response.request.fromCache) {
140-
data['fromCache'] = true;
141-
}
142-
143126
return data;
144127

145128

146129
})
147130
.catch(async (error) => {
148-
logError(`AgilityCMS Fetch API ERROR: Request failed for ${reqConfig.baseURL}${reqConfig.url} ... ${error} ... Does the item exist?`)
131+
logError(`AgilityCMS Fetch API ERROR: Request failed for ${reqConfig.baseURL}${reqConfig.url} ... ${error}.`)
149132
});
150133
}
151134

src/content-fetch.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ import { isHttps } from './utils'
4949
* @param {string} config.guid - The guid that represents your instance.
5050
* @param {string} config.apiKey - The secret token that represents your application.
5151
* @param {boolean} [config.isPreview] - If your access token is for preview, then set this to true.
52-
* @param {Object} [config.caching] - Optional Caching options. Caching is disabled by default.
53-
* @param {number} [config.caching.maxAge] - In miliseconds. Default value is *0* (disabled). Recommeded value is *180000* (3 mins). Requests are cached in memory only (node or browser).
5452
* @param {string} [config.baseUrl] - Optionally override the default API Base Url.
5553
* @return {AgilityFetch.Client}
5654
* @example
@@ -71,12 +69,14 @@ function getApi(config) {
7169

7270
function validateConfigParams(configParams) {
7371

72+
if(configParams.caching) {
73+
console.warn('The built-in caching has been deprecated from @agility/content-fetch as of version `1.1.0`. The `caching` parameter will have no effect.');
74+
}
75+
7476
if(!configParams.guid || configParams.guid.length == 0) {
7577
throw new TypeError('You must provide an guid.');
7678
} else if(!configParams.apiKey || configParams.apiKey.length == 0) {
77-
throw new TypeError('You must provide an access token.');
78-
} else if(configParams.caching && isNaN(configParams.caching.maxAge)) {
79-
throw new TypeError('When specifying a cache maxAge, you must set a number value in miliseconds, i.e. 180000 (3 mins).');
79+
throw new TypeError('You must provide an access token.');
8080
} else if(configParams.baseUrl && !isHttps(configParams.baseUrl)) {
8181
throw new TypeError(`When specifying a baseUrl (${configParams.baseUrl}), it must be over HTTPs.`);
8282
} else {

test/apiClients.config.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ function createApiClientWithNewCdn() {
2222
return api;
2323
}
2424

25-
function createCachedApiClient() {
26-
var api = agility.getApi({
27-
guid: guid,
28-
apiKey: apiKeyFetch,
29-
caching: {
30-
maxAge: 5 * 60 * 1000 //==5mins
31-
}
32-
});
33-
return api;
34-
}
35-
3625
function createPreviewApiClient() {
3726
var api = agility.getApi({
3827
guid: guid,
@@ -44,7 +33,6 @@ function createPreviewApiClient() {
4433

4534
export {
4635
createApiClient,
47-
createCachedApiClient,
4836
createPreviewApiClient,
4937
createApiClientWithNewCdn
5038
}

test/getContentItem.tests.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const expect = chai.expect;
55
import {
66
createApiClient,
77
createPreviewApiClient,
8-
createCachedApiClient,
98
createApiClientWithNewCdn
109
} from './apiClients.config'
1110

@@ -50,32 +49,6 @@ describe('getContentItem:', function() {
5049
.catch(done);
5150
})
5251

53-
it('should retrieve a content item in live/fetch mode, then subsequent requests are returned from cache (memory)', function(done) {
54-
var api = createCachedApiClient();
55-
api.getContentItem({
56-
contentID: ref.updatesMadeToPublishedContentItemID,
57-
languageCode: 'en-us'
58-
})
59-
.then(function(contentItem) {
60-
61-
assert.strictEqual(contentItem.contentID, ref.updatesMadeToPublishedContentItemID, 'retrieved content item we asked for');
62-
assert.notExists(contentItem.fromCache, 'content item should not be served from cache on first request')
63-
64-
api.getContentItem({
65-
contentID: ref.updatesMadeToPublishedContentItemID,
66-
languageCode: 'en-us'
67-
})
68-
.then(function(contentItem2) {
69-
70-
assert.strictEqual(contentItem2.contentID, ref.updatesMadeToPublishedContentItemID, 'retrieved content item we asked for');
71-
assert.strictEqual(contentItem2.fromCache, true, 'content item was retrieved from memory cache')
72-
done();
73-
})
74-
.catch(done)
75-
76-
})
77-
.catch(done);
78-
})
7952

8053
it('should throw error if contentID not passed as argument for getContentItem', function(done) {
8154
expect(function() {

test/getContentList.tests.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const expect = chai.expect;
44
import {
55
createApiClient,
66
createPreviewApiClient,
7-
createCachedApiClient,
87
createApiClientWithNewCdn
98
} from './apiClients.config'
109

test/getSyncContentItems.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import chai from 'chai'
22
const assert = chai.assert;
33
const expect = chai.expect;
44

5-
import { createApiClient, createPreviewApiClient, createCachedApiClient } from './apiClients.config'
5+
import { createApiClient, createPreviewApiClient } from './apiClients.config'
66
import { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } from 'constants';
77

88
/*

test/getSyncPageItems.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import chai from 'chai'
22
const assert = chai.assert;
33
const expect = chai.expect;
44

5-
import { createApiClient, createPreviewApiClient, createCachedApiClient } from './apiClients.config'
5+
import { createApiClient, createPreviewApiClient } from './apiClients.config'
66
import { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } from 'constants';
77

88
/*

0 commit comments

Comments
 (0)