Skip to content

Expire values in RedisCacheAdapter #2988

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

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/Adapters/Cache/RedisCacheAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import redis from 'redis';
import logger from '../../logger';

const DEFAULT_REDIS_TTL = 30 * 1000; // 30 seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we use this here so could be removed.

Currently the schema cache TTL is passed in to ParseServer as schemaCacheTTL and then passed to the adapter with each put(). However InMemoryCache does have a default TTL if no value is passed in from the adapter, so you might want to implement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arg, I had something there initially where if TTL wasn't provided we'd use one but the lockout tests wouldn't pass. I meant to remove that for the time being.


function debug() {
logger.debug.apply(logger, ['RedisCacheAdapter', ...arguments]);
}
Expand Down Expand Up @@ -33,9 +35,15 @@ export class RedisCacheAdapter {
debug('put', key, value, ttl);
this.p = this.p.then(() => {
return new Promise((resolve, _) => {
this.client.set(key, value, function(err, res) {
resolve();
});
if (ttl) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in InMemoryCache is a little different:
TTL = 0 means store but have immediately expire, e.g. in tests.
TTL = NaN means never expire.

Your change has TTL = 0 never expiring and I'm not sure what happens when NaN is passed to psetex().
I would change to match InMemoryCache

Copy link
Contributor Author

@TylerBrock TylerBrock Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thank you that was the piece of information I was looking for, I'll update.

I saw this login in the InMemory cache but assumed zero meant never expire not immediately expire. That's why the tests wouldn't pass.

this.client.psetex(key, ttl, value, function(err, res) {
resolve();
});
} else {
this.client.set(key, value, function(err, res) {
resolve();
});
}
});
});
return this.p;
Expand Down