Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

Global Value Cache

 

Global Value Cache is a centralized mechanism to cache data. Items in the cache are of Value type. Global Value Cache adjusts its size based on current system memory consumption.

 

Function List

 

Value MakeValue(ValueMaker& m)

Requests a Value. The Value is defined by instance of class derived from ValueMaker, which is class with two virtual methods:

 

virtual String Key() const;

virtual int Make(Value& object) const;

 

Key should return unique identifier for Value requested with ValueMaker derived class. Note that the type of ValueMaker derived class becomes a part of the key, so it is not necessary to add any info about the ValueMaker into the key. Make then creates the corresponding Value and returns the approximate memory consumption needed to store that Value. MakeValue first checks whether Value corresponding to given ValueMaker and Key are in the cache, if yes then it returns Value from the cache, otherwise calls ValueMaker::Make to obtain the Value and stores it to the cache. Note that this function allows full reentrancy (from various threads as well as recursive calls (through Make method) in single thread

 


 

bool IsValueCacheActive()

Returns true if it is still possible to use Value Cache. This special function is intended to solve destruction conflicts at the program exit.

 


 

void AdjustValueCache()

Adjusts cache limits based on system memory available. Maximum cache size is set to available_memory / 1024, maximum cached values count is set to available_memory / 1024 / 200. Note that CtrlCore (U++ GUI) normally calls this function after processing every GUI event.

 


 

void ShrinkValueCache()

Maintains the size of cache based on limit computed in the last AdjustValueCache call or setup with SetupValueCache.

 


 

void SetupValueCache(int maxsize, int maxcount)

Sets cache limits - maxsize in bytes and maxcount of cached values. If maxsize is zero, calls AdjustValueCache and any further calls to AdjustValueCache adjust it. If maxsize is greater than zero, limits are fixed to maxsize and maxcount.

 


 

template <class Pint ValueCacheRemove(P what)

Removes all Values from the cache that satisfy what predicate.

 


 

template <class Pint ValueCacheRemoveOne(P what)

Removes one Value from the cache that satisfy what predicate (simply removes the first one that it finds).

 


 

template <class Pvoid ValueCacheAdjustSize(P getsize)

Adjusts size information. getsize should return the memory size needed to store Value passed as parameter or it can return negative number to signal that the size has not changed. This is very specific function basically only needed to support PaintOnly Images.

 

Do you want to contribute?