OpenRoadCode
Public API reference for OpenRoadCode
Loading...
Searching...
No Matches
image.image_cache.ImageCache Class Reference

Downloads, decodes, resizes, and caches images. More...

Public Member Functions

int max_entries (self)
 Return the maximum number of decoded images retained.
Path|None cache_directory (self)
 Return the persistent source-image cache directory, if enabled.
int entry_count (self)
 Return the number of images currently cached.
Image.Image get (self, str url, *, int|None width=None, int|None height=None)
 Return an image from the cache or download it.
bool contains (self, str url, *, int|None width=None, int|None height=None)
 Return whether a matching decoded image is cached.
int remove (self, str url)
 Remove every cached image variant for a URL.
None clear (self)
 Remove all cached images.

Detailed Description

Downloads, decodes, resizes, and caches images.

Cached images are stored using a least-recently-used eviction policy.

Member Function Documentation

◆ contains()

bool image.image_cache.ImageCache.contains ( self,
str url,
* ,
int | None width = None,
int | None height = None )

Return whether a matching decoded image is cached.

Parameters
urlImage URL used as part of the cache key.
widthOptional bounding width used as part of the cache key.
heightOptional bounding height used as part of the cache key.
Return values
TrueAn exact URL/dimension variant is cached.
FalseNo exact variant is cached.

◆ entry_count()

int image.image_cache.ImageCache.entry_count ( self)

Return the number of images currently cached.

Returns
Current count of URL/dimension variants.

◆ get()

Image.Image image.image_cache.ImageCache.get ( self,
str url,
* ,
int | None width = None,
int | None height = None )

Return an image from the cache or download it.

When width or height is supplied, the image is resized while preserving its aspect ratio.

A copy of the cached image is returned so callers cannot mutate the cached instance.

Parameters
urlNon-empty HTTP or HTTPS image URL.
widthOptional positive bounding width in pixels.
heightOptional positive bounding height in pixels.
Returns
Caller-owned copy of the decoded image.
Exceptions
ValueErrorif the URL or dimensions are invalid.
ImageDownloadErrorif downloading or decoding fails.

◆ max_entries()

int image.image_cache.ImageCache.max_entries ( self)

Return the maximum number of decoded images retained.

Returns
Positive cache-entry limit.

◆ remove()

int image.image_cache.ImageCache.remove ( self,
str url )

Remove every cached image variant for a URL.

Parameters
urlURL whose dimension variants should be removed.
Returns
Number of removed cache entries.

The documentation for this class was generated from the following file:
  • controllers/image/image_cache.py