@onzag/itemize / Modules / server/cache / Cache
server/cache.Cache
The cache class that provides all the functionality that is specified for the cache package, the cache is more than what it name implies because it contains redis and it's the same in all the servers
- appData
- currentlySetting
- databaseConnection
- domain
- elastic
- listener
- memoryCache
- redisClient
- root
- sensitiveConfig
- serverData
- storageClients
- deletePossibleChildrenOf
- forceCacheInto
- getRaw
- getServerData
- onChangeInformed
- onChangeInformedNoData
- onServerDataChangeInformed
- pokeCache
- requestCopy
- requestCreation
- requestDelete
- requestListCache
- requestToken
- requestUpdate
- requestValue
- setAppData
- setListener
- setRaw
- triggerSearchListenersFor
- updatePointerMap
- wipe
• new Cache(redisClient, databaseConnection, elastic, sensitiveConfig, storageClients, domain, root, initialServerData): Cache
Builds a new cache instance, before the cache is ready it needs to be able to access the listener as well, but due to the fact that the listener depends on the cache as well it is instantiaded by te listener at the same time
| Name | Type | Description |
|---|---|---|
redisClient |
ItemizeRedisClient |
the redis client that is used for storing values |
databaseConnection |
DatabaseConnection |
- |
elastic |
ItemizeElasticClient |
- |
sensitiveConfig |
ISensitiveConfigRawJSONDataType |
- |
storageClients |
IStorageProvidersObject |
- |
domain |
string |
- |
root |
default |
the root of itemize |
initialServerData |
IServerDataType |
- |
• Private appData: IAppDataType
• Private currentlySetting: Object = {}
▪ [id: string]: { replacement: any ; valueBeingSet: any }
• Private databaseConnection: DatabaseConnection
• Private domain: string
• Private elastic: ItemizeElasticClient
• Private listener: Listener
• Private memoryCache: Object = {}
▪ [key: string]: { value: ISQLTableRowValue }
• Private redisClient: ItemizeRedisClient
• Private root: default
• Private sensitiveConfig: ISensitiveConfigRawJSONDataType
• Private serverData: IServerDataType
• Private storageClients: IStorageProvidersObject
▸ deletePossibleChildrenOf(itemDefinition, id, version): Promise<void>
Deletes all the possible children that might have been set as parent of the deleted item definition value
| Name | Type |
|---|---|
itemDefinition |
default |
id |
string |
version |
string |
Promise<void>
▸ forceCacheInto(idefTable, id, version, value, ensure): Promise<void>
forces a cached value for a given item definition table in an id and version
| Name | Type | Description |
|---|---|---|
idefTable |
string |
the item definition table or its qualified name |
id |
string |
the id |
version |
string |
the version or null |
value |
ISQLTableRowValue |
the value to store |
ensure |
boolean |
if true does not trust the value right away and checks it against the current value last modified signature and will only set it if it's older (newer) |
Promise<void>
▸ getRaw<T>(key): Promise<{ value: T }>
Provides a cached value from its identifier
| Name |
|---|
T |
| Name | Type | Description |
|---|---|---|
key |
string |
the identifier |
Promise<{ value: T }>
a promise with the value
▸ getServerData(): IServerDataType
Provides the current server data
▸ onChangeInformed(itemDefinition, id, version, data?): Promise<void>
This function triggers once the remote listener has detected a change that has been done by another server instance to a value that we are supposedly currently holding in memory
| Name | Type | Description |
|---|---|---|
itemDefinition |
string |
the item definition qualified name |
id |
string |
the id of such |
version |
string |
the version or null |
data? |
ISQLTableRowValue |
the entire SQL result |
Promise<void>
a void promise when done
▸ onChangeInformedNoData(itemDefinition, id, version): Promise<void>
When a change has been informed from the cluster that other cluster has made but it provides no data about what has changed and it needs to be manually fetched
| Name | Type |
|---|---|
itemDefinition |
string |
id |
string |
version |
string |
Promise<void>
▸ onServerDataChangeInformed(newData): void
This function is called once new server data was informed by a redis event
| Name | Type | Description |
|---|---|---|
newData |
IServerDataType |
the new server data that redis is giving |
void
▸ pokeCache(keyIdentifier): Promise<void>
Resets the expiration clock of a given identifier
| Name | Type | Description |
|---|---|---|
keyIdentifier |
string |
the identifier |
Promise<void>
▸ requestCopy(item, id, version, options?): Promise<ISQLTableRowValue>
Given an item that needs to be copied it will create a new copy for it with all its files and everything
| Name | Type | Description |
|---|---|---|
item |
string | default |
the item to copy from |
id |
string |
the id to copy from |
version |
string |
the version to copy from |
options |
ICopyOptions |
some options for side effects as this calls the request creation function |
Promise<ISQLTableRowValue>
▸ requestCreation(itemDefinition, value, options): Promise<ISQLTableRowValue>
Request the creation of a new item definition value for an specific item definition
| Name | Type | Description |
|---|---|---|
itemDefinition |
default |
the item definition we refer to |
value |
ISQLTableRowValue | IRQArgs | IRQValue |
the value to create, the value can be partial |
options |
ICreationOptions |
options as to create, some options are required |
Promise<ISQLTableRowValue>
▸ requestDelete(item, id, version, options?): Promise<void>
Request the deletition of an item definition value
| Name | Type | Description |
|---|---|---|
item |
string | default |
the item definition to delete a value for |
id |
string |
the id to delete for |
version |
string |
the version to delete for |
options |
IDeleteOptions |
- |
Promise<void>
▸ requestListCache(records): Promise<ISQLTableRowValue[]>
TODO Optimize this, right now it retrieves the list one by one Requests a whole list of search results
| Name | Type | Description |
|---|---|---|
records |
IRQSearchRecord[] |
the records to request for |
Promise<ISQLTableRowValue[]>
a list of whole sql combined table row values
▸ requestToken(id): Promise<string>
Provides a valid token for a given user, you might not really want to use this method unless you are fairly sure as these are permanent tokens for users for their given session id, normally you would use these tokens for redirected logins
| Name | Type | Description |
|---|---|---|
id |
string |
the user id |
Promise<string>
▸ requestUpdate(item, id, version, update, options): Promise<ISQLTableRowValue>
Requests an update for an item definition where new values are set for this existent item definition value, these are taken as instructions and no checks are done on it
| Name | Type | Description |
|---|---|---|
item |
string | default |
the item definition in question |
id |
string |
the id to update |
version |
string |
the version of that id to update |
update |
IRQArgs |
the update in question (partial values are allowed) |
options |
IUpdateOptions |
- |
Promise<ISQLTableRowValue>
a total combined table row value that can be converted into rq
▸ requestValue(item, id, version, options?): Promise<ISQLTableRowValue>
Requests a value from the cache
| Name | Type | Description |
|---|---|---|
item |
string | default |
the item definition or a qualified name |
id |
string |
the id to request for |
version |
string |
the version |
options |
Object |
- |
options.doNotEnsure? |
boolean |
- |
options.forceRefresh? |
boolean |
- |
options.useMemoryCache? |
boolean |
a total opposite of refresh, (do not use together as refresh beats this one) which will use a 1 second memory cache to retrieve values and store them, use this if you think the value might be used consecutively and you don't care about accuraccy that much |
options.useMemoryCacheMs? |
number |
- |
Promise<ISQLTableRowValue>
a whole sql value that can be converted into rq if necessary
▸ setAppData(appData): void
Allows to set the app data in the server side where this app is contained
| Name | Type | Description |
|---|---|---|
appData |
IAppDataType |
the app data |
void
▸ setListener(listener): void
Sets the listener for the remote interaction with the clients that are connected, this listener is what informs the client of updates the listener is highly related to the cache as it uses pubsub that comes from redis
| Name | Type | Description |
|---|---|---|
listener |
Listener |
the listener |
void
▸ setRaw(key, value, onConflict): Promise<void>
| Name | Type |
|---|---|
key |
string |
value |
any |
onConflict |
(value: any) => boolean |
Promise<void>
▸ triggerSearchListenersFor(itemDefinition, createdBy, newParent, originalParent, propertyMap, record, location): void
| Name | Type |
|---|---|
itemDefinition |
default |
createdBy |
string |
newParent |
Object |
newParent.id |
string |
newParent.type |
string |
newParent.version |
string |
originalParent |
Object |
originalParent.id |
string |
originalParent.type |
string |
originalParent.version |
string |
propertyMap |
IPropertyMapElement[] |
record |
IRQSearchRecord |
location |
"modified" | "new" | "deleted" |
void
▸ updatePointerMap(transactingDatabase, itemDefinition, id, version, pointerMap): Promise<ItemizeRawDB>
| Name | Type |
|---|---|
transactingDatabase |
DatabaseConnection |
itemDefinition |
default |
id |
string |
version |
string |
pointerMap |
IPropertyMapElementPointer[] |
Promise<ItemizeRawDB>
▸ wipe(): Promise<void>
wipes the cache, usually executed on edge cases during connectivity issues with clusters and nodes, once the connection is restablished with redis the cache is wiped by the cluster manager which handles the cache
Promise<void>