moleculerjs / moleculer

:rocket: Progressive microservices framework for Node.js
https://moleculer.services/
MIT License
6.09k stars 578 forks source link

Documentation on cache lock does not match the source #1252

Closed ponez closed 9 months ago

ponez commented 9 months ago

On https://moleculer.services/docs/0.14/caching#Cache-locking suggests that we can use

const broker = new ServiceBroker({  
    cacher: {  
        ttl: 60,  
        lock: true, // Set to true to enable cache locks. Default is disabled.  
    }  
});

But in base.js, we're checking that ts if (opts.lock.enabled !== false) so just passing a boolean won't work here and in another part, it says

const broker = new ServiceBroker({  
    cacher: {  
        ttl: 60,  
        lock: {  
            ttl: 15, // The maximum amount of time you want the resource locked in seconds  
            staleTime: 10, // If the TTL is less than this number, it means that the resources are staled  
        }  
    }  
});

but still, there's no enabled key until we reach the third part.

icebob commented 9 months ago

The lock: true is transferred to { enabled: true} the following code: https://github.com/moleculerjs/moleculer/blob/da2aabcc7e5254ac3ce2de689bac3ce3d16033b8/src/cachers/base.js#L324-L327