A cache is a least recently used (LRU) list of cache items. The cache items are accessed via \fCchar*\fR keys. For Unicode keys use the TQCache template instead, which uses TQString keys. A TQCache has the same performace as a TQAsciiCache.
Each cache item has a cost. The sum of item costs, totalCost(), will not exceed the maximum cache cost, maxCost(). If inserting a new item would cause the total cost to exceed the maximum cost, the least recently used items in the cache are removed.
.PP
Apart from insert(), by far the most important function is find() (which also exists as operator[]()). This function looks up an item, returns it, and by default marks it as being the most recently used item.
.PP
There are also methods to remove() or take() an object from the cache. Calling setAutoDelete(TRUE) tells the cache to delete items that are removed. The default is to not delete items when then are removed (i.e., remove() and take() are equivalent).
When inserting an item into the cache, only the pointer is copied, not the item itself. This is called a shallow copy. It is possible to make the cache copy all of the item's data (known as a deep copy) when an item is inserted. insert() calls the virtual function TQPtrCollection::newItem() for the item to be inserted. Inherit a cache and reimplement newItem() if you want deep copies.
When removing a cache item the virtual function TQPtrCollection::deleteItem() is called. Its default implementation in TQAsciiCache is to delete the item if auto-deletion is enabled.
Constructs a cache whose contents will never have a total cost greater than \fImaxCost\fR and which is expected to contain less than \fIsize\fR items.
.PP
\fIsize\fR is actually the size of an internal hash array; it's usually best to make it prime and at least 50% bigger than the largest expected number of items in the cache.
.PP
Each inserted item has an associated cost. When inserting a new item, if the total cost of all items in the cache will exceed \fImaxCost\fR, the cache will start throwing out the older (least recently used) items until there is enough room for the new item to be inserted.
If \fIcaseSensitive\fR is TRUE (the default), the cache keys are case sensitive; if it is FALSE, they are case-insensitive. Case-insensitive comparison only affects the 26 letters in US-ASCII. If \fIcopyKeys\fR is TRUE (the default), TQAsciiCache makes a copy of the cache keys, otherwise it copies just the const char * pointer - slightly faster if you can guarantee that the keys will never change, but very risky.
Returns the item with key \fIk\fR, or 0 if the key does not exist in the cache. If \fIref\fR is TRUE (the default), the item is moved to the front of the least recently used list.
.PP
If there are two or more items with equal keys, the one that was inserted last is returned.
Inserts the item \fId\fR into the cache using key \fIk\fR, and with an associated cost of \fIc\fR. Returns TRUE if the item is successfully inserted. Returns FALSE if the item is not inserted, for example, if the cost of the item exceeds maxCost().
The cache's size is limited, and if the total cost is too high, TQAsciiCache will remove old, least recently used items until there is room for this new item.
\fBWarning:\fR If this function returns FALSE, you must delete \fId\fR yourself. Additionally, be very careful about using \fId\fR after calling this function, because any other insertions into the cache, from anywhere in the application or within TQt itself, could cause the object to be discarded from the cache and the pointer to become invalid.
A debug-only utility function. Prints out cache usage, hit/miss, and distribution information using tqDebug(). This function does nothing in the release library.
Takes the item associated with \fIk\fR out of the cache without deleting it and returns a pointer to the item taken out, or 0 if the key does not exist in the cache.
.PP
If there are two or more items with equal keys, the one that was inserted last is taken.
.PP
All iterators that refer to the taken item are set to point to the next item in the cache's traversal order.