SUIT Framework

Scripting Using Integrated Templates

Docs - Cache

12/27/2015: SUIT Framework is no longer actively maintained.

One of the most common criticisms of projects like SUIT is that by adding "unnecessary" complication, they cause scripts to load slower than they would normally. While I'd like to say SUIT's parser works so efficiently that it doesn't take any extra time to process, it does slow scripts down by a couple fractions of a millisecond. While some might consider this negligble, others might consider it an excuse to avoid using SUIT along with its standards. For those people, SUIT has caching functions.

By default, SUIT caches the results to tokens and parse. This effictively eliminates the additional processing time whenever you execute the same template with the same rules.

Now, if your application runs on a constant Python process, that means this cache will not reset when you refresh the page. But, what if you want to take full effect of the caching features running a PHP application or a Python application that doesn't run constantly? Luckily, the SUIT's cache attribute can be accessed, encoded by JSON, stored to a file, loaded when you refresh, and decoded to use. See an example of this below:

$cache = file_get_contents('cache.json');
if ($cache)
    $suit->cache = json_decode($cache);
// Execute the string.
$string = $suit->execute($rules, $string);
// If the cache has grown, update the cache file.
$newcache = json_encode($suit->cache);
if ($cache != $newcache)
    file_put_contents('cache.json', $newcache);
import json
cache = open('cache.json').read()
if cache:
    suit.cache = json.loads(cache)
# Execute the string.
string = suit.execute(rules, string)
# If the cache has grown, update the cache file.
newcache = json.dumps(suit.cache)
if cache != newcache:

Some systems create a cache file for every template parsed. Not SUIT. Set up the cache like this, and you're good to go. Now, once you parse every template with every ruleset you use on you application, the cache should stay the same size. Changing the data that SUIT substitutes into these templates will not grow the cache. However, if you modify a template or change the ruleset that you use to transform it, the cache will start growing again. Because of this, it wouldn't be a bad idea to empty the cache file every once in a while.