#include <CacheEngine.hpp>
Every time a document is loaded, it is a good idea to declare it on the cache. The holder indexes the document address, and store an internal reference on the document content. Next time a document is requested, the cache will find the content in O(log N) time, avoiding downloading it again.
Typical usage is to attach a RequiredFetcherImplementation to the holder, so the holder can decide when to download a document.
Usually, the cache holder groups items in ItemGroup, from a same "root" URL. It's possible to query the group fetching advancement, in order to update a progress bar, or something like this.
The holder is monitoring the memory it uses, and as soon as the cached memory overcome a given limit, the holder will remove the oldest element from the cache until the limit is reached again (plus a given 10% margin and VAT).
Public Types | |
typedef Container::PlainOldData< volatile Item * >::Array | ItemGroup |
An item group declaration. | |
typedef Container::NotConstructible< ItemGroup >::ChainedList | ItemGroupList |
The list of item groups declaration. | |
Public Member Functions | |
ItemGroup * | addGroupFromRoot (const Strings::FastString &URL, void *opaque) |
Add a group to the cache with the given "root" URL. | |
bool | addItemToGroup (const Strings::FastString &URL, ItemGroup *group) |
Add an item to a group from the given URL. | |
bool | emptyCache (const uint32 size) |
Empty the cache to ensure the given amount of free bytes. | |
const bool | entireGroupReady (const ItemGroup *group) |
Check if a group is ready for presentation. | |
ItemGroup * | findGroupFromItem (volatile Item *item) |
Find a group containing the given item. | |
volatile Item * | findItemFromURL (const Strings::FastString &URL) |
Find an item from its URL. | |
ItemGroup * | findRoot (const Strings::FastString &URL) |
Find a root from a given URL. | |
const uint32 | getFetchingAdvancement (const ItemGroup *group, bool booleanResult=false) |
Check the advancement of a group fetching. | |
const bool | groupFetchingError (const ItemGroup *group) |
Check if there was a fatal error while fetching a group. | |
Holder (RequiredFetcherImplementation &_fetcher, const uint32 maxSize=33554432) | |
The only constructor. | |
virtual | ~Holder () |
The destructor. |
typedef Container::PlainOldData<volatile Item *>::Array Cache::Holder::ItemGroup |
An item group declaration.
typedef Container::NotConstructible<ItemGroup>::ChainedList Cache::Holder::ItemGroupList |
The list of item groups declaration.
Cache::Holder::Holder | ( | RequiredFetcherImplementation & | _fetcher, | |
const uint32 | maxSize = 33554432 | |||
) | [inline] |
The only constructor.
This constructor sets the fetcher, and the maximum allowed size before pruning the oldest element from cache
_fetcher | A reference on a fecther implementation | |
maxSize | The maximum allowed size in bytes (default is 32MB) |
virtual Cache::Holder::~Holder | ( | ) | [inline, virtual] |
The destructor.
ItemGroup* Cache::Holder::addGroupFromRoot | ( | const Strings::FastString & | URL, | |
void * | opaque | |||
) | [inline] |
Add a group to the cache with the given "root" URL.
The "root" URL is fetched.
URL | The URL to fetch. URL is UTF8 encoded | |
opaque | An opaque object that could be used to pass any structure from the cache to the fetcher |
bool Cache::Holder::addItemToGroup | ( | const Strings::FastString & | URL, | |
ItemGroup * | group | |||
) | [inline] |
Add an item to a group from the given URL.
The item URL is fetched.
URL | The URL to fetch. URL is UTF8 encoded | |
group | The group to add this item to. |
bool Cache::Holder::emptyCache | ( | const uint32 | size | ) | [inline] |
Empty the cache to ensure the given amount of free bytes.
size | The free size to get when exiting |
const bool Cache::Holder::entireGroupReady | ( | const ItemGroup * | group | ) | [inline] |
Check if a group is ready for presentation.
This method is very similar to getFetchingAdvancement, expect the return is boolean. This call is non blocking, as long as the fetcher's isItemFetched is not
group | The ItemGroup pointer to inspect |
Find a group containing the given item.
item | The item pointer to look for |
volatile Item* Cache::Holder::findItemFromURL | ( | const Strings::FastString & | URL | ) | [inline] |
Find an item from its URL.
URL | The URL to look for. URL is UTF8 encoded |
ItemGroup* Cache::Holder::findRoot | ( | const Strings::FastString & | URL | ) | [inline] |
Find a root from a given URL.
URL | The URL to fetch. URL is UTF8 encoded |
const uint32 Cache::Holder::getFetchingAdvancement | ( | const ItemGroup * | group, | |
bool | booleanResult = false | |||
) | [inline] |
Check the advancement of a group fetching.
This call is non blocking, as long as the fetcher's isItemFetched is not
group | The ItemGroup pointer to inspect | |
booleanResult | Does the result be 0 or 100 only, or can it spread over the whole range (whole range by default). |
const bool Cache::Holder::groupFetchingError | ( | const ItemGroup * | group | ) | [inline] |
Check if there was a fatal error while fetching a group.
This can happen if root-level items have failed to fetch
group | The ItemGroup pointer to inspect |