Search the site

With TradePoint 3.1 came the Cache object which can be used to optimize your site extensively. To allow easy interaction with the cache object, we also supply a couple of helpful scriplet methods as described below.

Standard Caching

To utilize the cache functionality you have 2 methods you need to use with some parameters.

Reference

MiscUtils.GetCache( name, cacheMode, ignoreLocalization )
name             String. A unique id for the cache
cacheMode   Numeric.
0                    No caching
1                    Cache is shared by all users
2                    Cache per user
3                    Cache for anonymous users
4                    Cache per user, authenticated users only
ignoreLocalization              Boolean

MiscUtils.SetCache(name, value, [timeout], cachemode, ignoreLocalization)
name             String. A unique id for the cache
value             String. The data to cache
timeout          Optional Numeric. In minutes
cacheMode   Numeric.
0                    No caching
1                    Cache is shared by all users
2                    Cache per user
3                    Cache for anonymous users
4                    Cache per user, authenticated users only
ignoreLocalization              Boolean.

Example

// Try to get the cached data
var cachedData = MiscUtils.GetCache( "TheBigList", 1, true );
if(!cachedData)
{
    // the data could not be found in the cache, generate it
    cachedData = MyScriptlet.theFunctionThatDoesTheBigThing();
    
    // store the data in the cache
    MiscUtils.SetCache( "TheBigList", cachedData, null, 1, true);
}

// write the data to the Response
Response.write( cachedData );

Clearing the cache

You can explicitly clear a cache if you do not wish to wait for the time out.

 MiscUtils.ClearCache( "TheBigList", 1, true );

Fragment Caching

Fragment caching is used to cache complex outputs instead of having to create large strings to contain the output. Just tell the Cache to begin recording and then tell it to stop when you are done.

Call BeginFragmentCache() to mark beginning of captured and cached output sequence. If there is no cached data, false is returned and recording begins and will end when EndFragment() is called. If the named fragment is already cached, true is returned and the cache is automatically written to the Response.

To mark the end of a fragment, use EndFragmentCache(). This will write the newly cached fragment to the Response.

Cached fragments can be nested but will only be cached in the outermost fragment, i.e. the nested fragments will be ignored but not cause errors.

Reference  

MiscUtils.BeginFragmentCache(name, cacheMode, ignoreLocalization)
Name            String. A unique id for the cache
cacheModeNumeric.
0                    No caching
1                    Cache is shared by all users
2                    Cache per user
3                    Cache for anonymous users
4                    Cache per user, authenticated users only
ignoreLocalization              Boolean.

Example   

if (MiscUtils.BeginFragmentCache('A'))
{
    Response.Write('toodles!');
    MiscUtils.EndFragmentCache();
}

Example: Caching ERP-queries in TradePoint

A common action in TradePoint is to cache the queries from the ERP-system (for example Dynamics NAV) and because of this caching has been added as optional parameters to the ERP-call.

Reference

MiscUtils.InvokeTP(p1, p2, p3, p4, p5, [cacheMode], [cacheMinutes])
P1..p5            These are the standard parameters not related to caching
cacheMode   Optional. Numeric.
0                    No caching
1                    Cache is shared by all users
2                    Cache per user
3                    Cache for anonymous users
4                    Cache per user, authenticated users only
cacheMinutes                      Optional. Numeric in minutes

 




Published by: Henrik Weimenhög / scriptserver.com