Cache Management How To's

From Pengower
Jump to: navigation, search

Cache management offers the ability to store items in memory rather than in the database between user requests. This functionality has been added to improve performance where an item is constructed over the course of more than one request from the user e.g. the building up of a sales order from a number of scanned or entered objects. It will also help with database concurrency issues under similar performance critical scenarios.

The cache of objects is managed on a user by user basis and there is therefore no cross over between the objects stored – two users could store items of the same in the cache and the platform would ensure that each accessed the correct object/s.

How to Add Items into Cache

Syntax; Cache Add Key = ”[key value]”, Value = [variable name]

This command will add the entity associated with variable ‘[variable name]’ into the Cache under key ‘[key value]’. Note, the code assumes that [variable name] will be an entity variable or array variable.

The variable being added can either be a single entity variable or an array of entity variables. Note, adding an item to the cache will replace any existing entry with that key.


Set per = Do New Object Params Type = “Person”
Set per[“Name”] = “Gordon Brown”
Cache Add Key = ”Gordon”, Value = per
Set pets = {}
Set eddi = Do New Object Params Type = “Pet”
Set eddi[“Type”] = “Dog”
Set eddi[“Name”] = “Eddi”
Add eddi To pets
Set lily = Do New Object Params Type = “Pet”
Set lily[“Type”] = “Dog”
Set lily[“Name”] = “Lily”
Add lily To pets
Cache Add Key = “Dogs”, Value = pets

How to Get Items from Cache

Syntax; Set [output var] = Cache Get Key = “[key value]”

This command will retrieve an entity or array of entities from the Cache. The key value will represent the key under which the entity was /entities were originally stored. If the key is not present in the Cache a NULL variable will be returned.


Set per = Cache Get Key=”Gordon”
Set pets = Cache Get Key = “Dogs”

How to Clear Item/Items from Cache

Syntax; Cache Clear Key = “[key value]”

This command will clear a given entry out of the Cache.


Cache Clear Key =”Gordon”

How to Purge the Cache

Syntax; Cache Purge

This command will purge all existing entries in the Cache. Note, the Cache is populated on a user by user basis, i.e. each logged on user has a cache of their own.


Cache Purge

How to use Cached Arrays In Group Display

The memory cache aims to tackle two key problems; (i) limits to the number of items that can be output in an array from scripts and; (ii) speed issues when working with purely temporary objects that don’t require db storage.

One issue is how to display information on these cached objects on forms and in objects. To this end the display of Groups on forms has been adapted to display arrays of cached entities.

When a group attempts to render on a form it checks to see if an array of entities is stored in under a key that matches the group name in the memory cache. If this is the case the group renders the array of entities in the cache.

To implement this functionality create a group with a specific name e.g. “People”. In script store an array of entities into the cache under the same key. Output a custom form that contains a group element attached to the “People” group.

Note: The output of arrays from script also makes use of the memory cache to get around the limit of ten items that has existed prior to v4.0 of the script engine.

When an array is assigned to the output of a script the script engine utilises the memory cache to display the array of entities, and the number of entities that can be displayed is now unlimited. Please not that pagination is not enabled in this case and so the number of items should be limited purely on grounds of download performance.