InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MResourceFileCacheX Class Reference

#include <mresourcefilecachex.h>

Public Types

enum  { kDefaultRFCacheLength = 8, kDefaultMaxBundleCount = 50, kDefaultMaxResourceCount = 50 }
 

Public Member Functions

void CacheBundle (NSString *identifier, NSBundle *bundle)
 
NSBundle * GetCachedBundle (NSString *identifier)
 
void RemoveBundle (NSString *identifier)
 
NSData * GetCachedResourceData (const IDFile &resourceFile)
 
void RemoveResourceData (const IDFile &resourceFile)
 
void SetMaxBundleCount (uint32 count)
 
void SetMaxResourceCount (uint32 count)
 
void ClearCache ()
 
bool16 DisableUnloading (bool16 disable=kTrue)
 
void CacheResourceData (const IDFile &resourceFile, NSData *data)
 
void CloseResourceFile (const IDFile &resourceFile)
 
void CloseUnusedFiles ()
 

Static Public Member Functions

static MResourceFileCacheXGetSharedCache ()
 

Static Public Attributes

static MResourceFileCacheX fResourceFileCache
 

Detailed Description

Implementation of a cache for resource bundles and files This provides efficient caching of NSBundle resources and maintains compatibility with legacy resource handling. The cache is thread-safe and handles automatic cleanup of unused resources.

For modern resource handling, use the bundle-based methods:

  • CacheBundle/GetCachedBundle for bundle management
  • GetCachedResourceData for accessing resource data
  • RemoveBundle/ClearCache for cleanup

The cache implements an eviction policy based on:

  • Maximum number of entries (configurable)
  • Memory pressure (automatic)
  • Manual control through DisableUnloading

Caching happens behind the scenes and is transparent to almost all clients. The one exception is that a bug in the Mac OS X Nav services dialogs can clobber one of our resource files if we have any unused but cached resource files. To avoid this call MResourceFileCacheX::fResourceFileCache.CloseUnusedFiles() to empty the cache of unused files just prior to using a Nav Services dialog, and at the end of any callbacks that might cause a resource file to be opened or closed

See Also
ResourceEnabler, MResourceAccess

Member Function Documentation

void MResourceFileCacheX::CacheBundle (NSString * identifier,
NSBundle * bundle 
)

Cache a bundle with its identifier

void MResourceFileCacheX::CacheResourceData (const IDFileresourceFile,
NSData * data 
)

Legacy support for resource file handling

void MResourceFileCacheX::ClearCache ()

Clear all cached bundles and resource data

bool16 MResourceFileCacheX::DisableUnloading (bool16 disable = kTrue)

Flag to disable unloading of cached but unused resources

NSBundle* MResourceFileCacheX::GetCachedBundle (NSString * identifier)

Get a cached bundle by identifier

NSData* MResourceFileCacheX::GetCachedResourceData (const IDFileresourceFile)

Get cached resource data for a file

static MResourceFileCacheX& MResourceFileCacheX::GetSharedCache ()
static

Get the shared cache instance

void MResourceFileCacheX::RemoveBundle (NSString * identifier)

Remove a bundle from the cache

void MResourceFileCacheX::RemoveResourceData (const IDFileresourceFile)

Remove resource data from cache

void MResourceFileCacheX::SetMaxBundleCount (uint32 count)

Set maximum number of bundles to cache

void MResourceFileCacheX::SetMaxResourceCount (uint32 count)

Set maximum number of resource data entries to cache

Member Data Documentation

MResourceFileCacheX MResourceFileCacheX::fResourceFileCache
static

Provides access to the resource cache