hapijs / catbox

Multi-strategy object caching service
Other
494 stars 72 forks source link

Can't drop method without arguments #165

Closed KeKs0r closed 7 years ago

KeKs0r commented 8 years ago

Hi, I am trying to drop a method that has no arguments.

If that is the case the id is an empty string. Which is not an issue for policy.set:

   const id = (key && typeof key === 'object') ? key.id : key;
    this._cache.set({ segment: this._segment, id: id }, value, ttl, (err) => {

https://github.com/hapijs/catbox/blob/master/lib/policy.js#L237-L238

But if I want to invalidate the same, I get an Error:

    const id = (key && typeof key === 'object') ? key.id : key;
    if (!id) {
        return callback(new Error('Invalid key'));
    }

    this._cache.drop({ segment: this._segment, id: id }, (err) => {

https://github.com/hapijs/catbox/blob/master/lib/policy.js#L257-L262

Is it possible to remove the id check?

KeKs0r commented 8 years ago

I found a workaround which solves it. Just generate a static key:

        server.method('getCurrentGames', getCurrentGames, {
            bind: server,
            cache: {
                cache: 'redis',
                expiresIn: 1000 * 60 * 3,
                staleIn: 1000 * 60,
                staleTimeout: 10000,
                generateTimeout: 1000 * 5
            },
            generateKey: function (array) {
                return 'main';
            }
        });

I still think its not consistent, that set allows it, but not drop.

tsuz commented 7 years ago

Hi @hueniverse

I couldn't find the contribution guide and made a PR for this bug. Let me know if it requires any more detail!

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.