ImageUrlCacheInterface Class Reference

#include <imageurlcache.h>

Inheritance diagram for ImageUrlCacheInterface:

Detailed Description

Cache class to allow delayed load of images with notification when it's ready to display. Multiple requests are combined (the first request loads the image and notifies all others)

Public Types

using UpdateCacheDelegate = Delegate< Result< void >(const Url &url, const ImageBaseRef &loaded)>
 

Public Member Functions

 MAXON_OBSERVABLE (void, ObservableFreeCache,(const Url &url), ObservableCombinerRunAllComponent)
 
MAXON_METHOD Result< Opt< ImageBaseRef > > GetImage (UpdateCacheDelegate &&updateDelegate) const
 
MAXON_METHOD Result< Opt< ImageBaseRef > > GetImage (UpdateCacheDelegate &&updateDelegate, Bool async) const
 

Static Public Member Functions

static MAXON_METHOD Result< void > InvalidateCache (const Url &url)
 
static MAXON_METHOD Result< ImageUrlCacheRef > FindOrCreate (const Url &url)
 

Private Member Functions

 MAXON_INTERFACE (ImageUrlCacheInterface, MAXON_REFERENCE_NORMAL, "net.maxon.image.interface.imageurlcache")
 

Member Typedef Documentation

◆ UpdateCacheDelegate

using UpdateCacheDelegate = Delegate<Result<void>(const Url& url, const ImageBaseRef& loaded)>

Delegate which is called if the cache was updated.

Parameters
[in]urlurl of the image
[in]loadedImageBaseRef with the loaded image.

Member Function Documentation

◆ MAXON_INTERFACE()

MAXON_INTERFACE ( ImageUrlCacheInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.image.interface.imageurlcache"   
)
private

◆ InvalidateCache()

static MAXON_METHOD Result<void> InvalidateCache ( const Url url)
static

InvalidateCache invalidates and removed the image from the cache. The next request will reload the image.

Parameters
[in]urlImage to discard from the cache.
Returns
OK on success.

◆ FindOrCreate()

static MAXON_METHOD Result<ImageUrlCacheRef> FindOrCreate ( const Url url)
static

FindOrCreate returns the cache for the requested image resource.

Parameters
[in]urlUrl of the image to load.
Returns
Cache on success.

◆ MAXON_OBSERVABLE()

MAXON_OBSERVABLE ( void  ,
ObservableFreeCache  ,
(const Url &url)  ,
ObservableCombinerRunAllComponent   
)

◆ GetImage() [1/2]

MAXON_METHOD Result<Opt<ImageBaseRef> > GetImage ( UpdateCacheDelegate &&  updateDelegate) const

GetImage returns the image from the cache, if there is one. If nullptr then the image is still loading. In that case the delegate is triggered once the image is loaded.

Parameters
[in]updateDelegateDelegate which is called once the image is loaded.
Returns
Image or nullptr on success.

◆ GetImage() [2/2]

MAXON_METHOD Result<Opt<ImageBaseRef> > GetImage ( UpdateCacheDelegate &&  updateDelegate,
Bool  async 
) const

GetImage returns the image from the cache, if there is one. If nullptr then the image is still loading. In that case the delegate is triggered once the image is loaded.

Parameters
[in]updateDelegateDelegate which is called once the image is loaded.
[in]asyncUse false to force synchronous loading, by default loading is asynchronous.
Returns
Image or nullptr on success.