Cache::Holder Class Reference

#include <CacheEngine.hpp>

List of all members.


Detailed Description

This class defines the cache holder.

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).

See also:
RequiredFetcherImplementation, Item


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

ItemGroupaddGroupFromRoot (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.
ItemGroupfindGroupFromItem (volatile Item *item)
 Find a group containing the given item.
volatile ItemfindItemFromURL (const Strings::FastString &URL)
 Find an item from its URL.
ItemGroupfindRoot (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.


Member Typedef Documentation

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.


Constructor & Destructor Documentation

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

Parameters:
_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.


Member Function Documentation

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.

Parameters:
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
Returns:
An ItemGroup pointer that can be used later on, to add elements to the group, or 0 on error

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.

Parameters:
URL The URL to fetch. URL is UTF8 encoded
group The group to add this item to.
Returns:
true on success, or false on error

bool Cache::Holder::emptyCache ( const uint32  size  )  [inline]

Empty the cache to ensure the given amount of free bytes.

Parameters:
size The free size to get when exiting
Returns:
true on success, false if there is not enough room is cache to find the given amount

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

See also:
RequiredFetcherImplementation::isItemFetched
Parameters:
group The ItemGroup pointer to inspect
Returns:
true if all documents of a group are fetched, false otherwise

ItemGroup* Cache::Holder::findGroupFromItem ( volatile Item item  )  [inline]

Find a group containing the given item.

Parameters:
item The item pointer to look for
Returns:
An ItemGroup pointer if found, or 0 on error

volatile Item* Cache::Holder::findItemFromURL ( const Strings::FastString URL  )  [inline]

Find an item from its URL.

Parameters:
URL The URL to look for. URL is UTF8 encoded
Returns:
An item pointer if found, 0 else

ItemGroup* Cache::Holder::findRoot ( const Strings::FastString URL  )  [inline]

Find a root from a given URL.

Parameters:
URL The URL to fetch. URL is UTF8 encoded
Returns:
An ItemGroup pointer that can be used later on, to add elements to the group, or 0 on error

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

See also:
RequiredFetcherImplementation::isItemFetched
Parameters:
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).
Returns:
The fetching sum percentage between 0 and 100. If no information is known about item size, the returned value is always 0 (not finished) or 100 (finished)

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

See also:
RequiredFetcherImplementation::isItemFetched
Parameters:
group The ItemGroup pointer to inspect
Returns:
true if the group is not going to finish fetching, false otherwise


The documentation for this class was generated from the following file:

(C) An X-Ryl669 project 2007

This document describes Unlimited Zooming Interface source code. UZI stands for Unlimited Zooming Interface, and source code license is