.. _technical:

Technical
=========
The following documents some technical details about smartCache. Most probably
interesting for TDs.

Creating cache files
--------------------
All rendered images and their hash values get written into a cache directory.
Click the ``reveal cache`` button on a cache node to reveal its cache
directory. smartCache creates a manifest file for every frame in the cache
directory. It detects all upstream dependent nodes of the node to cache and
writes a separate ``.json`` file that contains all dependent nodes for every
cached frame.

For each node it keeps record of all knob values. Any node or knob listed in
the 'ignore' fields as defined in the `settings <settings.html>`_ gets ignored. By default
smartCache ignores some nodes like 'Dot' and 'NoOp' nodes that don't contribute
to the output image but server more for structural reasons. The same applies to
several knobs that don't change the image output, e.g. xpos and ypos. The
actual node position does not change the rendered image output so any node
position change does not affect the cache validity. There are several other
knobs like ``label``, ``dope_sheet``, ``bookmark``, ``help``,
``postage_stamp``, ``gl_color``, ``tile_color``, etc. that get ignored as well.
The user can update nodes and knobs to ignore as needed in the ignore section
in the settings.

Once a manifest has been written, we create a hash sum of this ``.json`` file
and store a node-knob-setup hash for each frame in a ``hash.json`` file. By
default, smartCache keeps all manifest files on disk. But if you want to save
some storage space, the manifest can also be deleted automatically by setting
the environment variable ``CRAGL_SMARTCACHE_DELETE_SETUP_SOURCE_FILE`` to
``True``.

When creating a cache, we store the hashes in a ``master`` folder. Clicking the
``check cache validity`` creates the same procedure in a folder with the
current timestamp. smartCache compares the hashes of the master ``hash.json``
to the ``hash.json`` of the current timestamp to perform a frame by frame
validity check. Any frame's hash that does not correlate to the master hash
will be marked as outdated.

.. image:: img/technical/cash_folder_content.png