Downloads, decodes, resizes, and caches images.
More...
|
| 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.
|
Downloads, decodes, resizes, and caches images.
Cached images are stored using a least-recently-used eviction policy.
◆ 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
-
| url | Image URL used as part of the cache key. |
| width | Optional bounding width used as part of the cache key. |
| height | Optional bounding height used as part of the cache key. |
- Return values
-
| True | An exact URL/dimension variant is cached. |
| False | No 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
-
| url | Non-empty HTTP or HTTPS image URL. |
| width | Optional positive bounding width in pixels. |
| height | Optional positive bounding height in pixels. |
- Returns
- Caller-owned copy of the decoded image.
- Exceptions
-
| ValueError | if the URL or dimensions are invalid. |
| ImageDownloadError | if 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
-
| url | URL 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