infinity.memory¶
Provides a thread-safe shared memory within one INFINITY.JS instance.
All functions in this namespace read and write data to a shared memory in a thread-safe manner, by implicitly locking memory access (multiple-read, single-write). You can, however, also lock shared memory access explicitly, e.g. for grouping multiple read and/or write operations together, without other threads interfering with them. If you use the lock function to do so, always make sure that you unlock all namespaces you've locked, or otherwise your program will run into deadlocks and will not properly terminate (since the operating system will wait for it to release all locks it holds).
Note: if you are using the expiry parameter when putting data then make sure to call infinity.memory.flushExpired() in a regular interval (e.g. in a thread) so that expired values will be cleared. Expired entries remain readable until they are flushed.
Note: the typed functions store typed values: a value stored with putNumber()/addNumber() has to be read with getNumber(), a value stored with putBoolean() with getBoolean(), a list stored with putList()/addList() with getList(). put()/add() store the value as JSON text, which get() parses again (getString() returns the JSON text). Reading a value with a getter that does not match its stored type throws an error. All getters return undefined if the key does not exist.
Namespaces are created automatically on first use. Keys are kept sorted, so cursor iterates them in key order.
Module: infinity.memory
- add
- addBoolean
- addList
- addNumber
- addString
- clear
- decrement
- delList
- dump
- exists
- flushExpired
- get
- getBoolean
- getCount
- getList
- getMaxCount
- getMaxSize
- getNumber
- getSize
- getString
- getUpdateExpireOnAccess
- increment
- lock
- put
- putBoolean
- putList
- putNumber
- putString
- remove
- setMaxCount
- setMaxSize
- setUpdateExpireOnAccess
- unlock
Example:
infinity.loadModule('infinity.memory');
infinity.memory.lock('users');
try {
infinity.memory.put('users', 'id:1', {id: 1, username: 'tf', name: 'Tobias Frie', email: 'recipientName@domain.com'});
infinity.memory.putNumber('users', 'u:tf', 1);
infinity.memory.putNumber('users', 'recipientName@domain.com', 1);
} finally {
infinity.memory.unlock('users');
}
let id = infinity.memory.getNumber('users', 'u:tf');
console.debug(infinity.memory.get('users', 'id:' + id));
let cursor = new infinity.memory.cursor('users');
if (cursor.first()) {
do {
console.debug(cursor.key);
} while (cursor.next());
}
cursor.free();
cursor¶
The cursor class serves, similar to database result set cursors, for orientation while iterating through the specified namespace (in key order). It points at the current entry and can be moved forward, backward and be reset to start and end positions. The cursor holds a read lock on the namespace until free() is called (or the object is garbage collected), so other threads cannot write to the namespace in the meantime. Always call free() as soon as possible; the cursor must not be used anymore afterwards (its methods throw an error since 3.11).
Properties:
Methods:
Example:
infinity.loadModule('infinity.memory');
let myCursor = new infinity.memory.cursor('testNamespace');
Properties
key¶
Type: string
Gets the name of the key the cursor is currently pointing at.
value¶
Type: any
Gets the value of the key the cursor is currently pointing at, parsed from JSON (for values stored with put() or add()).
valueAsBoolean¶
Type: boolean
Gets the value of the key the cursor is currently pointing at as a boolean (for values stored with putBoolean()/addBoolean(); throws an error for other types).
valueAsNumber¶
Type: number
Gets the value of the key the cursor is currently pointing at as a number (for values stored with putNumber()/addNumber(); throws an error for other types).
valueAsString¶
Type: string
Gets the value of the key the cursor is currently pointing at as a string (for string values, i.e. also the JSON text of values stored with put(); throws an error for other types).
Methods
constructor()¶
Lets you create an INFINITY.JS memory cursor object instance.
Signature:
constructor( namespace: string )
Parameters:
- namespace:
stringThe namespace to be read.
Example:
infinity.loadModule('infinity.memory');
let myCursor = new infinity.memory.cursor('testNamespace');
findExact()¶
Searches for the entry with exactly the specified key and puts the cursor on its position. Returns false if the key does not exist. Available since 3.11.
Signature:
findExact( key: string ): boolean
Parameters:
- key:
stringThe key to be searched for.
Return type: boolean
Example:
myCursor.findExact('id:1');
findFirst()¶
Searches for the first entry in memory the key of which starts with the specified characters and puts the cursor on its position.
Signature:
findFirst( key: string ): boolean
Parameters:
- key:
stringThe key to be examined.
Return type: boolean
Example:
myCursor.findFirst('id:1');
findLast()¶
Searches for the last entry in memory the key of which starts with the specified characters and puts the cursor on its position.
Signature:
findLast( key: string ): boolean
Parameters:
- key:
stringThe key to be examined.
Return type: boolean
Example:
myCursor.findLast('id:1');
findNext()¶
Can be used with findFirst() and findLast(): it searches for the next entry in memory, the key of which starts with the specified characters and puts the cursor on its position. If neither findFirst() nor findLast() has been used before the call of findNext(), the function behaves just like next().
Signature:
findNext(): boolean
Return type: boolean
Example:
infinity.loadModule('infinity.memory');
infinity.memory.add('testNamespace', 'id:1', 'anyData');
infinity.memory.add('testNamespace', 'id:2', 'anyData');
infinity.memory.add('testNamespace', 'key:1', 'anyData');
infinity.memory.add('testNamespace', 'id:3', 'anyData');
let myCursor = new infinity.memory.cursor('testNamespace');
if (myCursor.findFirst('id:')) {
do {
console.debug(myCursor.key);
} while (myCursor.findNext());
}
//id:1
//id:2
//id:3
myCursor.free();
findPrev()¶
Can be used with findFirst() and findLast(): it searches for the previous entry in memory, the key of which starts with the specified characters and puts the cursor on its position. If neither findFirst() nor findLast() has been used before the call of findPrev(), the function behaves just like prev().
Signature:
findPrev(): boolean
Return type: boolean
Example:
infinity.loadModule('infinity.memory');
infinity.memory.add('testNamespace', 'id:1', 'anyData');
infinity.memory.add('testNamespace', 'id:2', 'anyData');
infinity.memory.add('testNamespace', 'key:1', 'anyData');
infinity.memory.add('testNamespace', 'id:3', 'anyData');
let myCursor = new infinity.memory.cursor('testNamespace');
if (myCursor.findLast('id:')) {
do {
console.debug(myCursor.key);
} while (myCursor.findPrev());
}
//id:3
//id:2
//id:1
myCursor.free();
first()¶
Resets the cursor to the first position of the current namespace. Returns false if the namespace is empty.
Signature:
first(): boolean
Return type: boolean
Example:
myCursor.first();
free()¶
Frees the memory previously occupied by the memory cursor object instance and releases its read lock on the namespace. The cursor must not be used anymore afterwards.
Signature:
free(): void
Example:
myCursor.free();
last()¶
Moves the cursor to the last position of the current namespace. Returns false if the namespace is empty.
Signature:
last(): boolean
Return type: boolean
Example:
myCursor.last();
next()¶
Moves the cursor one entry forward. Returns false if there is no further entry.
Signature:
next(): boolean
Return type: boolean
Example:
myCursor.next();
prev()¶
Moves the cursor one entry backward. Returns false if there is no previous entry.
Signature:
prev(): boolean
Return type: boolean
Example:
myCursor.prev();
listArray¶
Extends: Array<any>
An array of any elements.
add()¶
Writes the given data (as JSON) to the specified namespace and key in memory, only if there is no data yet. Returns true if the value has been added, false if the key already exists.
Signature:
add( namespace: string, key: string, value: any, expire?: number ): boolean
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to write at.
-
value:
anyThe value to write.
-
expire:
number, optionalThe amount of seconds for the entry to be valid.
Return type: boolean
Example:
infinity.loadModule('infinity.memory');
if ( infinity.memory.add('testNamespace', 'id:1', 'anyData') ) {
//...
}
addBoolean()¶
Writes a boolean value to the specified namespace and key in memory, only if there is no data yet. Returns true if the value has been added, false if the key already exists.
Signature:
addBoolean( namespace: string, key: string, value: boolean, expire?: number ): boolean
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to write at.
-
value:
booleanThe value to write.
-
expire:
number, optionalThe amount of seconds for the entry to be valid.
Return type: boolean
Example:
infinity.loadModule('infinity.memory');
if ( infinity.memory.addBoolean('testNamespace', 'id:1', true) ) {
//...
}
addList()¶
Appends a value to the list stored at the specified namespace and key in memory. If the key does not exist yet, a new list containing the value is created. The value is appended as one list element (an array is appended as a nested array). Read the list with getList(). If expire is given, it is set for the whole list.
Signature:
addList( namespace: string, key: string, value: any, expire?: number ): void
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to write at.
-
value:
anyThe value to write.
-
expire:
number, optionalThe amount of seconds for the entry to be valid.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.addList('testNamespace', 'ids', 35);
infinity.memory.addList('testNamespace', 'ids', 'myStringData');
console.debug(infinity.memory.getList('testNamespace', 'ids'));
//[35,"myStringData"]
addNumber()¶
Writes a number to the specified namespace and key in memory, only if there is no data yet. Returns true if the value has been added, false if the key already exists.
Signature:
addNumber( namespace: string, key: string, value: number, expire?: number ): boolean
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to write at.
-
value:
numberThe value to write.
-
expire:
number, optionalThe amount of seconds for the entry to be valid.
Return type: boolean
Example:
infinity.loadModule('infinity.memory');
if ( infinity.memory.addNumber('testNamespace', 'id:1', 35) ) {
//...
}
addString()¶
Writes a string to the specified namespace and key in memory, only if there is no data yet. Returns true if the value has been added, false if the key already exists.
Signature:
addString( namespace: string, key: string, value: string, expire?: number ): boolean
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to write at.
-
value:
stringThe value to write.
-
expire:
number, optionalThe amount of seconds for the entry to be valid.
Return type: boolean
Example:
infinity.loadModule('infinity.memory');
if ( infinity.memory.addString('testNamespace', 'id:1', 'myStringData') ) {
//...
}
clear()¶
Deletes all entries from the specified namespace. If no namespace is given, all namespaces are cleared.
Signature:
clear( namespace?: string ): void
Parameters:
- namespace:
string, optionalThe namespace to be cleared.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.clear('testNamespace');
decrement()¶
Atomically decrements an integer counter inside the specified namespace and key and returns the new value. The counter can also be a number stored with putNumber() (it is truncated to an integer). Throws an error if the key contains a value of another type. If the key does not exist, the counter starts at 0, so the result is -value (until 3.11: 2147483647, independent of value). Decrementing removes an expiration setting of the entry. Read the counter with getNumber().
Signature:
decrement( namespace: string, key: string, value?: number ): number
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key which should contain the counter.
-
value:
number, optionalSpecifies the integer value to be subtracted from the existing counter. Default:
1.
Return type: number
Example:
infinity.loadModule('infinity.memory');
let counter = infinity.memory.decrement('testNamespace', 'id:1');
delList()¶
Deletes the first element equal to the given value (same JSON text) from the specified list stored in memory (see putList() and addList()). If the list becomes empty, the key is removed. Returns true if the value has been found and deleted, otherwise false.
Signature:
delList( namespace: string, key: string, value: any, expire?: number ): boolean
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key containing the list to be altered.
-
value:
anyThe value to be deleted.
-
expire:
number, optionalThe amount of seconds for the remaining list to be valid.
Return type: boolean
Example:
infinity.loadModule('infinity.memory');
infinity.memory.lock('testNamespace');
infinity.memory.putList('testNamespace', 'id:1', [35, 'myStringData', true]);
infinity.memory.delList('testNamespace', 'id:1', 'myStringData');
console.debug(infinity.memory.getList('testNamespace', 'id:1'));
infinity.memory.unlock('testNamespace');
//[35,true]
dump()¶
Returns the contents of the specified namespace as an object with the keys as property names. Values are returned as stored: numbers and booleans as such, values stored with put()/add() and lists as their JSON text.
Signature:
dump( namespace: string ): object
Parameters:
- namespace:
stringThe namespace to be dumped.
Return type: object
Example:
infinity.loadModule('infinity.memory');
let contents = infinity.memory.dump('testNamespace');
exists()¶
Specifies whether the given key does exist in the specified namespace.
Signature:
exists( namespace: string, key: string, keyStart?: boolean ): boolean
Parameters:
-
namespace:
stringThe namespace to be examined.
-
key:
stringThe key being searched for.
-
keyStart:
boolean, optionalWhether to search for any key that starts with the characters specified in "key".
Return type: boolean
Example:
infinity.loadModule('infinity.memory');
if ( infinity.memory.exists('testNamespace', 'id:1') ) {
//...
}
flushExpired()¶
Deletes entries from memory, which expiration timestamps have expired, from the specified namespace or, if no namespace is given, from all namespaces. A namespace is only checked if the last check has been more than 10 seconds ago; more frequent calls have no effect.
Signature:
flushExpired( namespace?: string ): void
Parameters:
- namespace:
string, optionalThe namespace to be flushed.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.flushExpired('testNamespace');
get()¶
Returns the value of the given key and namespace, if previously stored with put() or add(), or undefined if the key does not exist. Resets any expiration setting if present and if setUpdateExpireOnAccess() has not been set to false.
Signature:
get( namespace: string, key: string ): any
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to read from.
Return type: any
Example:
infinity.loadModule('infinity.memory');
let dataFromMemory = infinity.memory.get('testNamespace', 'id:1');
getBoolean()¶
Returns the boolean value of the specified namespace and key, if previously set with putBoolean() or addBoolean(), or undefined if the key does not exist. Resets any expiration setting, if present and if setUpdateExpireOnAccess() has not been set to false.
Signature:
getBoolean( namespace: string, key: string ): boolean
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to read from.
Return type: boolean
Example:
infinity.loadModule('infinity.memory');
let booleanValueFromMemory = infinity.memory.getBoolean('testNamespace', 'id:1');
getCount()¶
Returns the amount of entries stored inside the specified namespace.
Signature:
getCount( namespace: string ): number
Parameters:
- namespace:
stringThe namespace to be examined.
Return type: number
Example:
infinity.loadModule('infinity.memory');
let entriesInMemory = infinity.memory.getCount('testNamespace');
getList()¶
Returns the list stored at the specified namespace and key as a infinity.memory.listArray, if previously stored with putList() or addList(), or undefined if the key does not exist. Resets any expiration settings, if present and if setUpdateExpireOnAccess() has not been set to false.
Signature:
getList( namespace: string, key: string ): infinity.memory.listArray
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to read from.
Return type: infinity.memory.listArray
Example:
infinity.loadModule('infinity.memory');
let listFromMemory = infinity.memory.getList('testNamespace', 'id:1');
getMaxCount()¶
Gets the maximum number of entries for the specified namespace, as set by setMaxCount(). 0 means no limit (default).
Signature:
getMaxCount( namespace: string ): number
Parameters:
- namespace:
stringThe namespace to be examined.
Return type: number
Example:
infinity.loadModule('infinity.memory');
let namespaceMaxCount = infinity.memory.getMaxCount('testNamespace');
getMaxSize()¶
Gets the maximum size in bytes for the specified namespace, as set by setMaxSize(). 0 means no limit (default).
Signature:
getMaxSize( namespace: string ): number
Parameters:
- namespace:
stringThe namespace to be examined.
Return type: number
Example:
infinity.loadModule('infinity.memory');
let namespaceMaxSize = infinity.memory.getMaxSize('testNamespace');
getNumber()¶
Returns the number value of the specified namespace and key, if previously set with putNumber(), addNumber(), increment() or decrement(), or undefined if the key does not exist. Resets any expiration settings, if present and if setUpdateExpireOnAccess() has not been set to false.
Signature:
getNumber( namespace: string, key: string ): number
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to read from.
Return type: number
Example:
infinity.loadModule('infinity.memory');
let numberFromMemory = infinity.memory.getNumber('testNamespace', 'id:1');
getSize()¶
Returns the (approximate) size of the namespace in bytes, as used for setMaxSize().
Signature:
getSize( namespace: string ): number
Parameters:
- namespace:
stringThe namespace to be examined.
Return type: number
Example:
infinity.loadModule('infinity.memory');
let size = infinity.memory.getSize('testNamespace');
getString()¶
Returns the string contents of the specified namespace and key, if previously set with putString() or addString() (for values stored with put(), add() or as list, the JSON text is returned), or undefined if the key does not exist. Resets any expiration settings, if present and if setUpdateExpireOnAccess() has not been set to false.
Signature:
getString( namespace: string, key: string ): string
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to read from.
Return type: string
Example:
infinity.loadModule('infinity.memory');
let stringFromMemory = infinity.memory.getString('testNamespace', 'id:1');
getUpdateExpireOnAccess()¶
Gets the value set by setUpdateExpireOnAccess().
Signature:
getUpdateExpireOnAccess( namespace: string ): boolean
Parameters:
- namespace:
stringThe namespace to be examined.
Return type: boolean
Example:
infinity.loadModule('infinity.memory');
if ( infinity.memory.getUpdateExpireOnAccess('testNamespace') ) {
//...
}
increment()¶
Atomically increments an integer counter inside the specified namespace and key and returns the new value. If the key does not exist, the counter starts at 0, so the result is value (until 3.11: always 1, independent of value). The counter can also be a number stored with putNumber() (it is truncated to an integer). Throws an error if the key contains a value of another type. Incrementing removes an expiration setting of the entry. Read the counter with getNumber().
Signature:
increment( namespace: string, key: string, value?: number ): number
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key which should contain the counter.
-
value:
number, optionalSpecifies the integer value to be added to the existing value. Default:
1.
Return type: number
Example:
infinity.loadModule('infinity.memory');
let counter = infinity.memory.increment('testNamespace', 'id:1');
lock()¶
Locks the namespace for reading and/or writing. Locking a namespace for read-only access will halt script execution until there is no other thread holding a write-lock on that same namespace. There can be multiple read-only locks by different threads at the same time, but only one write-lock. Locking a namespace for write access will halt script execution until there is no other thread holding a read- or write-lock on that same namespace.
This method can be used to ensure atomic operations on shared memory without threads interfering with each other (much like transactions in a database).
Note: all infinity.memory functions are thread-safe, but if you need to read and/or write multiple values without another thread changing data in between, then you can use the lock method to explicitly lock a certain namespace.
Attention: you must always unlock a namespace you have locked. Otherwise you will block all other threads, and in addition to that, your program will not terminate correctly, since the operating system will wait for your program to release all locks it holds. Therefore you should always use try-finally blocks to ensure you release your locks.
The function returns true if the namespace has been locked by this call. It returns false if the current thread already holds a lock on this namespace; in this case nothing is locked additionally and you must not call unlock() for this call (otherwise the outer lock would be released). Requesting a write lock while the current thread holds a read lock on the same namespace throws an error.
Signature:
lock( namespace: string, readOnly?: boolean ): boolean
Parameters:
-
namespace:
stringThe namespace to be locked.
-
readOnly:
boolean, optionalWhether to lock the namespace for reading only. Default:
false(write lock).
Return type: boolean
Example:
infinity.loadModule('infinity.memory');
let namespace = 'testNamespace';
if ( infinity.memory.lock(namespace) ) { // lock namespace
try {
//...
} finally {
infinity.memory.unlock(namespace); // always unlock the namespace
}
}
put()¶
Writes the given data (as JSON) to the specified namespace and key in memory, overwriting any data previously stored there. The stored value can be read with get().
Signature:
put( namespace: string, key: string, value: any, expire?: number ): void
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to write to.
-
value:
anyThe value to write.
-
expire:
number, optionalThe amount of seconds for the entry to be valid.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.put('testNamespace', 'id:1', 'anyData');
putBoolean()¶
Writes a boolean value to the specified namespace and key in memory, overwriting any data previously stored there. The stored value can only be read with getBoolean().
Signature:
putBoolean( namespace: string, key: string, value: boolean, expire?: number ): void
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to write to.
-
value:
booleanThe value to write.
-
expire:
number, optionalThe amount of seconds for the entry to be valid.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.putBoolean('testNamespace', 'id:1', true);
putList()¶
Writes a infinity.memory.listArray to the specified namespace and key in memory, overwriting any data previously stored there. The stored value can only be read with getList(). Throws a TypeError if value is not an array.
Signature:
putList( namespace: string, key: string, value: infinity.memory.listArray, expire?: number ): void
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to write to.
-
value:
infinity.memory.listArrayThe value to write.
-
expire:
number, optionalThe amount of seconds for the entry to be valid.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.putList('testNamespace', 'id:1', [35, 'myStringData', true]);
putNumber()¶
Writes a number to the specified namespace and key in memory, overwriting any data previously stored there. The stored value can only be read with getNumber().
Signature:
putNumber( namespace: string, key: string, value: number, expire?: number ): void
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to write to.
-
value:
numberThe value to write.
-
expire:
number, optionalThe amount of seconds for the entry to be valid.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.putNumber('testNamespace', 'id:1', 35);
putString()¶
Writes a string to the specified namespace and key in memory, overwriting any data previously stored there. The stored value can only be read with getString().
Signature:
putString( namespace: string, key: string, value: string, expire?: number ): void
Parameters:
-
namespace:
stringThe namespace to operate in.
-
key:
stringThe key to write to.
-
value:
stringThe value to write.
-
expire:
number, optionalThe amount of seconds for the entry to be valid.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.putString('testNamespace', 'id:1', 'myStringData');
remove()¶
Removes the given key inside the specified namespace. Nothing happens if the key does not exist.
Signature:
remove( namespace: string, key: string, keyStart?: boolean ): void
Parameters:
-
namespace:
stringThe namespace to remove the key from.
-
key:
stringThe key to remove.
-
keyStart:
boolean, optionalWhether to remove any key that starts with the characters specified in "key".
Example:
infinity.loadModule('infinity.memory');
infinity.memory.remove('testNamespace', 'id:1');
setMaxCount()¶
Sets the maximum number of entries for the specified namespace to hold. When a new key is added and the namespace contains more entries than this limit, the oldest entries (in the order they have been added) are removed. Only entries added after the limit has been set are taken into account. 0 means no limit (default).
Signature:
setMaxCount( namespace: string, value: number ): void
Parameters:
-
namespace:
stringThe namespace to be limited.
-
value:
numberThe number of entries not to be exceeded.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.setMaxCount('testNamespace', 1000);
setMaxSize()¶
Sets the maximum size in bytes (see getSize()) for the specified namespace. When a new key is added and the namespace is larger than this limit, the oldest entries (in the order they have been added) are removed. Only entries added while a limit (setMaxSize() or setMaxCount()) is set are tracked for removal. Before 3.11, setMaxSize() only had an effect in combination with setMaxCount(). 0 means no limit (default).
Signature:
setMaxSize( namespace: string, value: number ): void
Parameters:
-
namespace:
stringThe namespace to be limited.
-
value:
numberThe size in bytes not to be exceeded.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.setMaxCount('testNamespace', 100000);
infinity.memory.setMaxSize('testNamespace', 10485760);
setUpdateExpireOnAccess()¶
Sets whether the expiration time of memory entries should be restarted when they are read. The default setting is true: entries with an expire value expire after this number of seconds without access. With false, they expire this number of seconds after they have been written.
Signature:
setUpdateExpireOnAccess( namespace: string, value: boolean ): void
Parameters:
-
namespace:
stringThe namespace for the setting to take effect.
-
value:
booleantruefor resetting the expiration settings on access,falsefor keeping them in effect.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.setUpdateExpireOnAccess('testNamespace', false);
unlock()¶
Unlocks the namespace locked by the current thread with lock(), allowing other threads to access it. Only call it if lock() has returned true.
Signature:
unlock( namespace: string ): void
Parameters:
- namespace:
stringThe namespace to be unlocked.
Example:
infinity.loadModule('infinity.memory');
infinity.memory.unlock('testNamespace');