Local and global cache

Local cache - saved data that is available only to the current script.

Global cache - is stored data that is available to all scripts and agents.

Methods for working with local cache:

  • IContext.StoreObject(...) - Write object to cache

  • IContext.LoadObject(...) - Load object from cache.

Methods for working with the global cache:

  • IContext.StoreGlobalObject(...) - Write an object to the global cache.

  • IContext.LoadGlobalObject(...) - Load object from global cache.

Important: the data cache is periodically cleared to free up space. In order for the data not to be deleted during the next compression, they need to be wrapped in the NotClearableContainer class.

An example with a global cache:

using TSLab.DataSource;
using TSLab.Script;
using TSLab.Script.Handlers;

namespace MyLib
    public class TestGlobalCashe : IExternalScript
        public void Execute(IContext ctx, ISecurity sec)
            // Write to global cache
            var value = 1.1; // value
            var key = "key"; // key in cache (any unique string)
            var container = new NotClearableContainer<double>(value);
            ctx.StoreGlobalObject(key, container);

            // Read from global cache
            var key2 = "key";
            var container2 = ctx.LoadGlobalObject(key2) as NotClearableContainer<double>;
            var value2 = container2?.Content;
            ctx.Log($"Value: {value2}", MessageType.Info, true);

Last updated