actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
60 lines (59 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CacheTest = void 0;
const index_1 = require("./../index");
class CacheTest extends index_1.Action {
constructor() {
super(...arguments);
this.name = "cacheTest";
this.description = "I will test the internal cache functions of the API";
this.inputs = {
key: {
required: true,
formatter: this.stringFormatter,
validator: this.stringValidator,
},
value: {
required: true,
formatter: this.stringFormatter,
validator: this.stringValidator,
},
};
this.outputExample = {
cacheTestResults: {
saveResp: true,
sizeResp: 1,
loadResp: {
key: "cacheTest_key",
value: "value",
createdAt: 1420953269716,
},
deleteResp: true,
},
};
}
stringFormatter(s) {
return String(s);
}
stringValidator(s) {
if (s.length < 3) {
return "inputs should be at least 3 letters long";
}
else {
return true;
}
}
async run({ params }) {
const key = `cacheTest_${params.key}`;
const value = params.value;
return {
cacheTestResults: {
saveResp: await index_1.cache.save(key, value, 5000),
sizeResp: await index_1.cache.size(),
loadResp: await index_1.cache.load(key),
deleteResp: await index_1.cache.destroy(key),
},
};
}
}
exports.CacheTest = CacheTest;