Object LruCache
LRU (least recently used) cache object
LruCache is used to maintain an LRU cache, the creation method:
1
2var util = require("util");
var c = new util.LruCache(10, 100);
Inheritance
Constructor
LruCache
LruCache object constructor
1
2new LruCache(Integer size,
Integer timeout = 0);
Call parameters:
- size: Integer, the maximum size of the cache
- timeout: Integer, the element expiration time, the unit is ms, no expiration if less than or equal to 0, the default is 0
Static properties
defaultMaxListeners
Integer, the default global maximum number of listeners
1static Integer LruCache.defaultMaxListeners;
Member attributes
size
Integer, query the number of values in the container
1readonly Integer LruCache.size;
timeout
Integer, query and set the expiration time of the element in the container, the unit is ms, and it will not fail if it is less than or equal to 0
1Integer LruCache.timeout;
onexpire
Function, query and bind data timeout event, equivalent to on("expire", func);
1Function LruCache.onexpire;
Member function
clear
Clear container data
1LruCache.clear();
has
Check whether there is data with the specified key value in the container
1Boolean LruCache.has(String name);
Call parameters:
- name: String, specify the key value to be checked
Return result:
- Boolean, Returns whether the key value exists
get
Query the value of the specified key
1Value LruCache.get(String name);
Call parameters:
- name: String, specify the key value to be queried
Return result:
- Value, Returns the value corresponding to the key value, if it does not exist, returns undefined
Query the value of the specified key value, if it does not exist or expires, call the callback function to update the data
1
2Value LruCache.get(String name,
Function updater);
Call parameters:
- name: String, specify the key value to be queried
- updater: Function, specify the update function
Return result:
- Value, Return the value corresponding to the key value
set
Set a key value data, insert a new data if the key value does not exist
1
2LruCache.set(String name,
Value value);
Call parameters:
- name: String, specify the key value to be set
- value: Value, specify the data to be set
Set a key value data, insert new data if the key value does not exist
1LruCache.set(Object map);
Call parameters:
- map: Object, specify the key-value data dictionary to be set
remove
Delete all values of the specified key value
1LruCache.remove(String name);
Call parameters:
- name: String, specify the key value to be deleted
isEmpty
Check if the container is empty
1Boolean LruCache.isEmpty();
Return result:
- Boolean, Return true if there is no value in the container
on
Bind an event handler to the object
1
2Object LruCache.on(String ev,
Function func);
Call parameters:
- ev: String, specify the name of the event
- func: Function, specify event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
Bind an event handler to the object
1Object LruCache.on(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
addListener
Bind an event handler to the object
1
2Object LruCache.addListener(String ev,
Function func);
Call parameters:
- ev: String, specify the name of the event
- func: Function, specify event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
Bind an event handler to the object
1Object LruCache.addListener(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
prependListener
Bind an event handler to the start of the object
1
2Object LruCache.prependListener(String ev,
Function func);
Call parameters:
- ev: String, specify the name of the event
- func: Function, specify event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
Bind an event handler to the start of the object
1Object LruCache.prependListener(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
once
Bind a one-time event processing function to the object, the one-time processing function will only be triggered once
1
2Object LruCache.once(String ev,
Function func);
Call parameters:
- ev: String, specify the name of the event
- func: Function, specify event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
Bind a one-time event processing function to the object, the one-time processing function will only be triggered once
1Object LruCache.once(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
prependOnceListener
Bind an event handler to the start of the object
1
2Object LruCache.prependOnceListener(String ev,
Function func);
Call parameters:
- ev: String, specify the name of the event
- func: Function, specify event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
Bind an event handler to the start of the object
1Object LruCache.prependOnceListener(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
off
Cancel the specified function from the object processing queue
1
2Object LruCache.off(String ev,
Function func);
Call parameters:
- ev: String, specify the name of the event
- func: Function, specify event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
Cancel all functions in the object processing queue
1Object LruCache.off(String ev);
Call parameters:
- ev: String, specify the name of the event
Return result:
- Object, Return the event object itself, which is convenient for chain call
Cancel the specified function from the object processing queue
1Object LruCache.off(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object property name is used as the event name, and the property value is used as the event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
removeListener
Cancel the specified function from the object processing queue
1
2Object LruCache.removeListener(String ev,
Function func);
Call parameters:
- ev: String, specify the name of the event
- func: Function, specify event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
Cancel all functions in the object processing queue
1Object LruCache.removeListener(String ev);
Call parameters:
- ev: String, specify the name of the event
Return result:
- Object, Return the event object itself, which is convenient for chain call
Cancel the specified function from the object processing queue
1Object LruCache.removeListener(Object map);
Call parameters:
- map: Object, specify the event mapping relationship, the object property name is used as the event name, and the property value is used as the event processing function
Return result:
- Object, Return the event object itself, which is convenient for chain call
removeAllListeners
Cancel all the listeners of all events from the object processing queue. If an event is specified, remove all the listeners of the specified event.
1Object LruCache.removeAllListeners(String ev);
Call parameters:
- ev: String, specify the name of the event
Return result:
- Object, Return the event object itself, which is convenient for chain call
Cancel all the listeners of all events from the object processing queue. If an event is specified, remove all the listeners of the specified event.
1Object LruCache.removeAllListeners(Array evs = []);
Call parameters:
- evs: Array, specify the name of the event
Return result:
- Object, Return the event object itself, which is convenient for chain call
setMaxListeners
The default limit of the number of listeners, only for compatibility
1LruCache.setMaxListeners(Integer n);
Call parameters:
- n: Integer, specify the number of events
getMaxListeners
Get the default limit of the number of listeners, only for compatibility
1Integer LruCache.getMaxListeners();
Return result:
- Integer, Return to the default limit number
listeners
Array of listeners for the specified event of the query object
1Array LruCache.listeners(String ev);
Call parameters:
- ev: String, specify the name of the event
Return result:
- Array, Returns an array of listeners for the specified event
listenerCount
The number of listeners for the specified event of the query object
1Integer LruCache.listenerCount(String ev);
Call parameters:
- ev: String, specify the name of the event
Return result:
- Integer, Returns the number of listeners for the specified event
The number of listeners for the specified event of the query object
1
2Integer LruCache.listenerCount(Value o,
String ev);
Call parameters:
- o: Value, specify the object of the query
- ev: String, specify the name of the event
Return result:
- Integer, Returns the number of listeners for the specified event
eventNames
Query the event name of the listener
1Array LruCache.eventNames();
Return result:
- Array, Returns an array of event names
emit
Trigger an event actively
1
2Boolean LruCache.emit(String ev,
...args);
Call parameters:
- ev: String, event name
- args: ..., event parameters, which will be passed to the event handler
Return result:
- Boolean, Return to the event trigger state, return true if there is a response event, otherwise return false
toString
Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics
1String LruCache.toString();
Return result:
- String, Returns the string representation of the object
toJSON
Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object
1Value LruCache.toJSON(String key = "");
Call parameters:
- key: String, unused
Return result:
- Value, Returns a value containing JSON serializable