Comments (6)
Thanks for your help, by reducing the code to a very basic version I actually found the issue :-) Now all works according to expectation.
The issue was in the initialization of the cache. I earlier did:
let cache = new NsqlCache({
db: dsAdapter(datastore),
stores: [
{
store: redisStore,
host: REDISHOST,
port: REDISPORT
}],
config: {
ttl: {
redis: {
keys: 60 * 60,
queries: 60 * 60
},
}
},
});
Replacing the code above with the following code made it all work:
const cacheStores = [ {
store: redisStore,
host: REDISHOST,
port: REDISPORT,
}];
const cacheConfig = {
ttl: {
redis: {
keys: 60 * 60,
queries: 60 * 60
}
}
};
let cache = {
stores: cacheStores,
config: cacheConfig
};
(Why the first version doesn't work I haven't investigated)
from gstore-node.
Thank you for the feedback @oander11 can you please add a code snippet so that we can recreate the issue? This will ensure that we properly resolve the issue and we can update our unit tests to ensure that the issue is properly addressed.
from gstore-node.
(I leave out boilerplate code for express etc) but the essential code is provided below.
When I do the Provider.get I get an object in the Redis cache with a name like: gck:1896000573. Since my first mail I have tried to manually clear the cache (see the commented rows in the code below) but I can't get those to work either. In the case where I get an exception (using clearCache with an id) the exception is:
TypeError: Cannot read property 'join' of undefined
at keyToString (/Users/olaepspot/code/infrastructure-service/node_modules/nsql-cache-datastore/lib/index.js:99:29)
at Object._db.keyToString.key [as keyToString] (/Users/olaepspot/code/infrastructure-service/node_modules/nsql-cache/lib/index.js:171:61)
at keyToString (/Users/olaepspot/code/infrastructure-service/node_modules/nsql-cache/lib/keys.js:17:60)
at cache.del.keys.map.k (/Users/olaepspot/code/infrastructure-service/node_modules/nsql-cache/lib/keys.js:208:54)
at Array.map (<anonymous>)
at Object.del (/Users/olaepspot/code/infrastructure-service/node_modules/nsql-cache/lib/keys.js:208:45)
at Function.clearCache (/Users/olaepspot/code/infrastructure-service/node_modules/gstore-node/lib/model.js:357:58)
at require.ProviderController.update (/Users/olaepspot/code/infrastructure-service/src/js/controllers/providerController.js:91:20)
ProviderController.js
ProviderController.get = async function (req, res) {
try {
let provider = await Provider.get(req.params.providerId);
if (!provider) throw { code: 404, detailcode: 125, message: 'No such item.' };
let jsonProvider = ModelService.processModel(req, provider); // just some basic processing of the data before returning
res.send(jsonProvider);
} catch (error) {
RouteService.handleError(res, error);
}
};
ProviderController.update = async function (req, res) {
try {
RoleService.verifyAccess(req, 'provider.update');
let data = Provider.sanitize(req.body);
console.log(data);
let updatedEntity = await Provider.update(req.params.providerId, data);
//await Provider.clearCache(); // this row has no effect
//await Provider.clearCache(req.params.providerId); // this row causes exception in gstore-node
let jsonEntity = ModelService.processModel(req, updatedEntity); // just some basic processing of the data
res.send(jsonEntity);
} catch (error) {
RouteService.handleError(res, error);
}
};
Initialization of cache etc
cache = new NsqlCache({
db: dsAdapter(datastore),
stores: [
/*{
store: 'memory',
max: 200,
},*/
{
store: redisStore,
host: REDISHOST,
port: REDISPORT
}],
config: {
ttl: {
/*memory: {
keys: 20, // 20s
queries: -1, // do not store queries in memory since they may be stale
},*/
redis: {
keys: 60 * 60, //1h
queries: 60 * 60
},
}
},
});
let gstore = null;
if (cache) gstore = new Gstore({cache: cache, errorOnEntityNotFound: false});
else gstore = new Gstore({errorOnEntityNotFound: false});
gstore.connect(datastore);
from gstore-node.
Oops, forgot to include the Provider Model I use, in case that is relevant:
const {gstore} = require('../util/storageService');
const { Schema } = gstore;
const validateAddress = require('./validation/validateAddress');
const validateContact = require('./validation/validateContact');
const providerSchema = new Schema({
name: { type: String, required: true },
invoiceEmail: { type: String, optional: true, validate: 'isEmail' },
contact: { type: Object, optional: true, validate: { rule: validateContact }},
supportContact: { type: Object, optional: true, validate: { rule: validateContact }},
address: { type: Object, optional: true, validate: { rule: validateAddress }},
imageAssets: { type: Array, optional: true }, // Array of Image Objects
providerAdmin: { type: Object, optional: true, write: false, validate: { rule: validateContact }},
createdOn: { type: Date, default: gstore.defaultValues.NOW, write: false, read: true},
legacyId: { type: String, write: false, read: false },
});
let _x = gstore.model('V2Provider', providerSchema);
export const Provider = _x;
from gstore-node.
@oander11 is there any way you could reduce this to a basic model with gstore-node only code (e.g. without express.js controllers)? Getting everything (e.g. ./util/storageService, ./validation/*, etc) setup so that we can recreate this is going to take a lot of guesswork and probably doesn't relate to the actual issue.
Ideally something like:
const { Gstore } = require('gstore-node');
// setup cache - https://sebloix.gitbook.io/gstore-node/cache-dataloader/cache#default-configuration
const gstore = new Gstore({
cache: {
stores: [ ... ],
config: { ... }
},
});
// model setup
// steps of gstore calls which fail
Also have you looked into whether the issue is with gstore-node or with nsql-cache? This would be one of the first things we need to sort out.
from gstore-node.
@oander11 glad we could inadvertently help. I can't immediately tell why the one would work and the other not, but it you figure it out please let us know.
from gstore-node.
Related Issues (20)
- query filter on nested property value. HOT 5
- tsc error: Could not find a declaration file for module 'nsql-cache' HOT 3
- could not get data filter by entity key
- Support for @google-cloud/datastore version 5 HOT 2
- Support for custom validators (AJV)
- bulk insert? HOT 2
- Cannot read property 'Symbol(KEY)' when body is null or undefined HOT 1
- Typescript Compile Error HOT 2
- Support for HABTM
- Could not find gstore instance with id "${id}" HOT 2
- How to validate a value agains another property? HOT 1
- Datastore Key type error when using cache HOT 7
- Add Transaction support to `findOne` option HOT 1
- Support filtering for a missing optional property. HOT 1
- New query operators HOT 1
- @google-cloud/datastore version 7 support HOT 1
- could not get data filter by entity key HOT 1
- Migrate Travis CI builds to Circle CI
- Gstore node 7.2.8 TypeError: OptionalDataloader is not a constructor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gstore-node.