#############################
Saving and Loading a GI Cache
#############################

GI caches can be directly saved in a .red file:

.. code:: cpp 
        
    // "red_file" is a pointer to an already open .red file.
    // "gi_cache" is a pointer to an existing GI cache.
    RED::IREDFile* ifile = red_file->As< RED::IREDFile >();

    RED::StreamingPolicy policy;
    RC_TEST( ifile->Write( gi_cache, policy, resmgr ) );

When GI caches are present in a loaded .red file, there are accessible through the ``RED::IDataManager`` interface in the Miscellaneous objects section:

.. code:: cpp 
        
    // "ctx" is the list of contexts created by loading the .red file.
    RED::IResourceManager* iresmgr = resmgr->As< RED::IResourceManager >();
    RED::IDataManager* idatamgr = iresmgr->GetDataManager()->As< RED::IDataManager >();

    // In this example, we assume that the GI cache is located in the first context at the first position:
    RC_TEST( idatamgr->GetMiscObject( gi_cache, ctx[0], 0 ) );