# glance.image_cache package

## Subpackages

- glance.image_cache.drivers package
  - Submodules
    - glance.image_cache.drivers.base module
      - `Driver`
    - glance.image_cache.drivers.centralized_db module
      - `Driver`
      - `delete_cached_file()`
    - glance.image_cache.drivers.common module
      - `SqliteConnection`
      - `dict_factory()`
      - `get_db()`
    - glance.image_cache.drivers.sqlite module
      - `Driver`
      - `delete_cached_file()`
    - glance.image_cache.drivers.xattr module
      - Assumptions
      - Cache Directory Notes
      - `Driver`
      - `delete_cached_file()`
      - `get_all_regular_files()`
      - `get_xattr()`
      - `inc_xattr()`
      - `set_xattr()`
  - Module contents

## Submodules

- glance.image_cache.base module
  - `CacheApp`
- glance.image_cache.cleaner module
  - `Cleaner`
    - `Cleaner.run()`
- glance.image_cache.client module
  - `CacheClient`
    - `CacheClient.DEFAULT_DOC_ROOT`
    - `CacheClient.DEFAULT_PORT`
    - `CacheClient.delete_all_cached_images()`
    - `CacheClient.delete_all_queued_images()`
    - `CacheClient.delete_cached_image()`
    - `CacheClient.delete_queued_image()`
    - `CacheClient.get_cached_images()`
    - `CacheClient.get_queued_images()`
    - `CacheClient.queue_image_for_caching()`
  - `get_client()`
- glance.image_cache.prefetcher module
  - `Prefetcher`
    - `Prefetcher.fetch_image_into_cache()`
    - `Prefetcher.run()`
- glance.image_cache.pruner module
  - `Pruner`
    - `Pruner.run()`

## Module contents

LRU Cache for Image Data

class glance.image_cache.ImageCache

  Bases: `object`

  Provides an LRU cache for image data.

  cache_image_file(image_id, image_file)

    Cache an image file.

    Parameters:

      - image_id – Image ID

      - image_file – Image file to cache

    Returns:

      True if image file was cached, False otherwise

  cache_image_iter(image_id, image_iter, image_checksum=None)

    Cache an image with supplied iterator.

    Parameters:

      - image_id – Image ID

      - image_file – Iterator retrieving image chunks

      - image_checksum – Checksum of image

    Returns:

      True if image file was cached, False otherwise

  cache_tee_iter(image_id, image_iter, image_checksum)
  clean(stall_time=None)

    Cleans up any invalid or incomplete cached images. The cache driver decides what that means…

  configure_driver()

    Configure the driver for the cache and, if it fails to configure, fall back to using the SQLite driver which has no odd dependencies

  delete_all_cached_images()

    Removes all cached image files and any attributes about the images and returns the number of cached image files that were deleted.

  delete_all_queued_images()

    Removes all queued image files and any attributes about the images and returns the number of queued image files that were deleted.

  delete_cached_image(image_id)

    Removes a specific cached image file and any attributes about the image

    Parameters:

      image_id – Image ID

  delete_queued_image(image_id)

    Removes a specific queued image file and any attributes about the image

    Parameters:

      image_id – Image ID

  get_cache_size()

    Returns the total size in bytes of the image cache.

  get_cached_images()

    Returns a list of records about cached images.

  get_caching_iter(image_id, image_checksum, image_iter)

    Returns an iterator that caches the contents of an image while the image contents are read through the supplied iterator.

    Parameters:

      - image_id – Image ID

      - image_checksum – checksum expected to be generated while iterating over image data

      - image_iter – Iterator that will read image contents

  get_hit_count(image_id)

    Return the number of hits that an image has

    Parameters:

      image_id – Opaque image identifier

  get_image_size(image_id)

    Return the size of the image file for an image with supplied identifier.

    Parameters:

      image_id – Image ID

  get_queued_images()

    Returns a list of image IDs that are in the queue. The list should be sorted by the time the image ID was inserted into the queue.

  init_driver()

    Create the driver for the cache

  is_cached(image_id)

    Returns True if the image with the supplied ID has its image file cached.

    Parameters:

      image_id – Image ID

  is_queued(image_id)

    Returns True if the image identifier is in our cache queue.

    Parameters:

      image_id – Image ID

  open_for_read(image_id)

    Open and yield file for reading the image file for an image with supplied identifier.

    :note Upon successful reading of the image file, the image’s

      hit count will be incremented.

    Parameters:

      image_id – Image ID

  prune()

    Removes all cached image files above the cache’s maximum size. Returns a tuple containing the total number of cached files removed and the total size of all pruned image files.

  queue_image(image_id)

    This adds a image to be cache to the queue.

    If the image already exists in the queue or has already been cached, we return False, True otherwise

    Parameters:

      image_id – Image ID

this page last updated: 2026-03-19 01:38:33

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug