Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added additional params for createcache. Allows description and expiry settings to be passed as arguments #176

Merged
merged 7 commits into from
Nov 11, 2019
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,10 @@ Creates a Cache with the given name.
#### Example
Create Cache map named "test-cache"

apigeetool createcache -u [email protected] -o sdoe -e test -z test-cache
apigeetool createcache -u [email protected] -o sdoe -e test -z test-cache --description "sample key" --cacheExpiryByDate 12-31-9999
hiteshshahjee marked this conversation as resolved.
Show resolved Hide resolved

apigeetool createcache -u [email protected] -o sdoe -e test -z test-cache --description "sample key" --cacheExpiryInSecs 40000

#### Required parameters

The following parameters are required. However, if any are left unspecified
Expand All @@ -951,9 +953,20 @@ for organization name, all of which are required.
`-z`
(required) The name of the cache to be created.

`--description`
hiteshshahjee marked this conversation as resolved.
Show resolved Hide resolved
(required) The description of the cache to be created.

`--environment -e`
(required) The environment to target.

Either of the following parameters are required to set the expiry settings
hiteshshahjee marked this conversation as resolved.
Show resolved Hide resolved

`--cacheExpiryByDate`
(either-required) Date by which the cache will expire. Date format must be mm-dd-yyyy.

`--cacheExpiryInSecs`
(either-required) Duration in seconds by which the cache will expire.

## <a name="Target Server Operations"></a>Target Server Operations

### <a name="createTargetServer"></a>createTargetServer
Expand Down
43 changes: 34 additions & 9 deletions lib/commands/createcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ var descriptor = defaults.defaultDescriptor({
name: 'Cache Resource',
shortOption: 'z',
required: true
}
},
description: {
name: 'Cache description',
required: true,
prompt: true
hiteshshahjee marked this conversation as resolved.
Show resolved Hide resolved
},
cacheExpiryByDate:{
hiteshshahjee marked this conversation as resolved.
Show resolved Hide resolved
name: 'Cache expiration by date (mm-dd-yyyy)',
required: false
},
cacheExpiryInSecs:{
hiteshshahjee marked this conversation as resolved.
Show resolved Hide resolved
name: 'Cache expiration in seconds',
required: false
}
});

module.exports.descriptor = descriptor;
Expand Down Expand Up @@ -45,15 +58,9 @@ function createCache(opts, request, done){
"compression" : {
"minimumSizeInKB" : 512
},
"description" : "Store Response",
"description" : opts.description,
hiteshshahjee marked this conversation as resolved.
Show resolved Hide resolved
"diskSizeInMB" : 1024,
"distributed" : true,
"expirySettings" : {
"expiryDate" : {
"value" : "12-31-9999"
},
"valuesNull" : false
},
hiteshshahjee marked this conversation as resolved.
Show resolved Hide resolved
"distributed" : true,
"inMemorySizeInKB" : 1024,
"maxElementsInMemory" : 100,
"maxElementsOnDisk" : 100,
Expand All @@ -63,6 +70,24 @@ function createCache(opts, request, done){
"skipCacheIfElementSizeInKBExceeds" : 512
}

var expirySettings = {};
if(opts.cacheExpiryByDate){
expirySettings = {
"expiryDate" : {
"value" : opts.cacheExpiryByDate
},
"valuesNull" : false
}
} else if(opts.cacheExpiryInSecs){
expirySettings = {
"timeoutInSec": {
"value": opts.cacheExpiryInSecs
},
"valuesNull": false
}
}
createCachePayload.expirySettings = expirySettings;

var uri = util.format('%s/v1/o/%s/e/%s/caches', opts.baseuri, opts.organization, opts.environment);
request({
uri: uri,
Expand Down