# BamCache

from pandac.PandaModules import BamCache

Class : BamCache
Description : This class maintains a cache of Bam and/or Txo objects generated from model files and texture images (as well as possibly other kinds of loadable objects that can be stored in bam file format).
This class also maintains a persistent index that lists all of the cached objects (see BamCacheIndex). We go through some considerable effort to make sure this index gets saved correctly to disk, even in the presence of multiple different processes writing to the same index, and without relying too heavily on low-level os-provided file locks (which work poorly with C++ iostreams).

## Inheritance:

BamCache:

## Methods of BamCache:

considerFlushIndex
flushIndex
getActive
getCacheMaxKbytes
getFlushTime
getGlobalPtr
getReadOnly
getRoot
lookup
setActive
setCacheMaxKbytes
setFlushTime
setReadOnly
setRoot
store

considerFlushIndex void BamCache::consider_flush_index(void); Description: Flushes the index if enough time has elapsed since the index was last flushed.

flushIndex void BamCache::flush_index(void); Description: Ensures the index is written to disk.

getActive bool BamCache::get_active(void) const; Description: Returns true if the BamCache is currently active, false if it is not. "active" means that the cache should be consulted automatically on loads, "not active" means that objects should be loaded directly without consulting the cache.

getCacheMaxKbytes int BamCache::get_cache_max_kbytes(void) const; Description: Returns the maximum size, in kilobytes, which the cache is allowed to grow to. See set_cache_max_kbytes().

getFlushTime int BamCache::get_flush_time(void) const; Description: Returns the time in seconds between automatic flushes of the cache index.

getGlobalPtr static BamCache *BamCache::get_global_ptr(void); Description: Returns a pointer to the global BamCache object, which is used automatically by the ModelPool and TexturePool.

getReadOnly bool BamCache::get_read_only(void) const; Description: Returns true if the cache is in read-only mode. Normally, the cache starts in read-write mode. It can put itself into read-only mode automatically if it discovers that it does not have write access to the cache.

getRoot Filename const &BamCache::get_root(void) const; Description: Returns the current root pathname of the cache. See set_root().

lookup PointerTo< BamCacheRecord > BamCache::lookup(Filename const &source_filename, string const &cache_extension); Description: Looks up a file in the cache. If the file is cacheable, then regardless of whether the file is found in the cache or not, this returns a BamCacheRecord. On the other hand, if the file cannot be cached, returns NULL. If record->has_data() returns true, then the file was found in the cache, and you may call record->extract_data() to get the object. If record->has_data() returns false, then the file was not found in the cache or the cache was stale; and you should reload the source file (calling record->add_dependent_file() for each file loaded, including the original source file), and then call record->set_data() to record the resulting loaded object; and finally, you should call store() to write the cached record to disk.

setActive void BamCache::set_active(bool flag); Filename: bamCache.I Created by: drose (09Jun06) PANDA 3D SOFTWARE Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved All use of this software is subject to the terms of the Panda 3d Software license. You should have received a copy of this license along with this source code; you will also find a current copy of the license at http://etc.cmu.edu/panda3d/docs/license/ . To contact the maintainers of this program write to panda3d-general@lists.sourceforge.net . Description: Changes the state of the active flag. "active" means that the cache should be consulted automatically on loads, "not active" means that objects should be loaded directly without consulting the cache.

setCacheMaxKbytes void BamCache::set_cache_max_kbytes(int max_kbytes); Description: Specifies the maximum size, in kilobytes, which the cache is allowed to grow to. If a newly cached file would exceed this size, an older file is removed from the cache. Note that in the case of multiple different processes simultaneously operating on the same cache directory, the actual cache size may slightly exceed this value from time to time due to latency in checking between the processes.

setFlushTime void BamCache::set_flush_time(int flush_time); Description: Specifies the time in seconds between automatic flushes of the cache index.

setReadOnly void BamCache::set_read_only(bool ro); Description: Can be used to put the cache in read-only mode, or take it out of read-only mode. Note that if you put it into read-write mode, and it discovers that it does not have write access, it will put itself right back into read-only mode.

setRoot void BamCache::set_root(Filename const &root); Description: Changes the current root pathname of the cache. This specifies where the cache files are stored on disk. This should name a directory that is on a disk local to the machine (not on a network-mounted disk), for instance, /tmp/panda-cache or /c/panda-cache. If the directory does not already exist, it will be created as a result of this call.

store bool BamCache::store(BamCacheRecord *record); Description: Flushes a cache entry to disk. You must have retrieved the cache record via a prior call to lookup(), and then stored the data via record->set_data(). Returns true on success, false on failure.