Skip to content

Error when replacing items #2

Description

@mkw

In lru-cache.js, the set function calls "this.get(key)" with no callback when replacing an item. At least in single user mode (possibly always) this will trigger an 'undefined is not a function' exception whenever an item is replaced.

To fix this, a check for the validity of the callback function should be added:

var LRUCacheProxy = function LRUCacheProxy(options) {
    if (!(this instanceof LRUCacheProxy)) {
        if(cluster.isMaster) {
            var lru = new LRUCache(options);
            var lruGet = LRUCache.prototype.get;

            lru.get = function(key, callback) {
                callback && callback(lruGet.apply(lru, arguments));
            };

            return lru;
        }

        return new LRUCacheProxy(options);
    }

    this.namespace = options.namespace || 'default';

    send(this.namespace, 'constructor', options, function() {});
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions