SysGlobalObjectCache(SGOC) is an LRU cache. This cache removes the least used data in order to make room for new data. The sysglobalobject cache is global across sessions and aos servers. The clearscope of cache is relayed to all aos servers and scope is cleared from all aos machines.

 

The cache is not managed by the kernel. It must be maintained by the application code. It’s the responsibility of the application code to clear the cache when not in use. The cache non hits are not routed to the db. SGOC stores key value pairs.

 

Its recommended that we put data that is not changing in the sgoc to improve the cache hits. The size of the SGOC is maintained as a parameter in the form server configuration. This value can be set for each server separately.

Below is the implementation of the pattern to use sgoc to cache data. Following are the artifacts

 

1)      Cachewrapper- eg.FooCache

2)      CacheScopeEnum- eg.FooCacheScope

 

The class FooCache manages the caching contract. It has methods to getvalue,insertvalue and clear the cache. The class has an associated enum FooCacheScope which is used to specify the scope. The enumvalue we are going to use is FooEnumValue1.

class FooCache
{
    public static void clearAllScopes()
    {
        DictEnum             dictEnum = new DictEnum(enumnum(FooCacheScope));
        int                  i;

        for (i = 0; i <= dictEnum.values(); i++)
        {
            FooCache::clearScope(dictEnum.index2Value(i));
        }
    }

    public static void clearScope(FooCacheScope _scope)
    {
        SysGlobalObjectCache c = classFactory.globalObjectCache();
        c.clear(FooCache::getCacheScopeStr(_scope));
    }

    private static str getCacheScopeStr(FooCacheScope _scope)
    {
       return 'FooCache_' + int2str(_scope);
    }

    public static container getValue(FooCacheScope _scope, container _key)
    {
        SysGlobalObjectCache c = classFactory.globalObjectCache();
        return c.find(FooCache::getCacheScopeStr(_scope), _key);
    }

    public static void insertValue(FooCacheScope _scope, container _key, container _value)
    {
        SysGlobalObjectCache c = classFactory.globalObjectCache();
        c.insert(FooCache::getCacheScopeStr(_scope), _key, _value);
    }

    public static void removeValue(FooCacheScope _scope, container _key)
    {
        SysGlobalObjectCache c = classFactory.globalObjectCache();
        c.remove(FooCache::getCacheScopeStr(_scope), _key);
    }

}

FooCacheScope enum has values FooEnumValue1 and FooEnumValue2.

 

Code to insert data to cache

FooCache::insertValue(fooCacheScope:: FooEnumValue1, [curext(), _key], [_value]);

Code to get value from cache

Container cacheResult = FooCache::getValue(fooCacheScope:: FooEnumValue1, [curext(), _key]);

Code to clear scope

FooCache::clearScope(FooCacheScope:: FooEnumValue1);