:right-sidebar: True FileCache =================================================================== .. currentmodule:: gi.repository.Shumate .. class:: FileCache(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` A cache that stores and retrieves tiles from the file system. It is mainly used by :obj:`~gi.repository.Shumate.TileDownloader`\, but can also be used by custom data sources. The cache will be filled up to a certain size limit. When this limit is reached, the cache can be purged, and the tiles that are accessed least are deleted. ETags -------------------------------------------------------------------------------- The cache can optionally store an ETag string with each tile. This is useful to avoid redownloading old tiles that haven't changed (for example, using the HTTP If-None-Match header). Constructors ------------ .. rst-class:: interim-class .. class:: FileCache :no-index: .. classmethod:: new_full(size_limit: int, cache_key: str, cache_dir: str | None = None) -> ~gi.repository.Shumate.FileCache Constructor of :obj:`~gi.repository.Shumate.FileCache`\. :param size_limit: maximum size of the cache in bytes :param cache_key: an ID for the tileset to store/retrieve :param cache_dir: the directory where the cache is created. When cache_dir == NULL, a cache in ~/.cache/shumate is used. Methods ------- .. rst-class:: interim-class .. class:: FileCache :no-index: .. method:: get_cache_dir() -> str Gets the directory where the cache database is stored. .. method:: get_cache_key() -> str Gets the key used to store and retrieve tiles from the cache. Different keys can be used to store multiple tilesets in the same cache directory. .. method:: get_size_limit() -> int Gets the cache size limit in bytes. .. method:: get_tile_async(x: int, y: int, zoom_level: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Gets tile data from the cache, if it is available. :param x: the X coordinate of the tile :param y: the Y coordinate of the tile :param zoom_level: the zoom level of the tile :param cancellable: a :obj:`~gi.repository.Gio.Cancellable` :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to execute upon completion :param user_data: closure data for ``callback`` .. method:: get_tile_finish(result: ~gi.repository.Gio.AsyncResult) -> ~typing.Tuple[~gi.repository.GLib.Bytes, str | None, ~gi.repository.GLib.DateTime | None] Gets the tile data from a completed :func:`~gi.repository.Shumate.FileCache.get_tile_async` operation. ``modtime`` will be set to the time the tile was added to the cache, or the latest time it was confirmed to be up to date. ``etag`` will be set to the data's ETag, if present. :param result: a :obj:`~gi.repository.Gio.AsyncResult` provided to callback .. method:: mark_up_to_date(x: int, y: int, zoom_level: int) -> None Marks a tile in the cache as being up to date, without changing its data. For example, a network source might call this function when it gets an HTTP 304 Not Modified response. :param x: the X coordinate of the tile :param y: the Y coordinate of the tile :param zoom_level: the zoom level of the tile .. method:: purge_cache_async(cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Removes less used tiles from the cache, if necessary, until it fits in the size limit. :param cancellable: a :obj:`~gi.repository.Gio.Cancellable` :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to execute upon completion :param user_data: closure data for ``callback`` .. method:: purge_cache_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Gets the result of an async operation started using :func:`~gi.repository.Shumate.FileCache.purge_cache_async`. :param result: a :obj:`~gi.repository.Gio.AsyncResult` provided to callback .. method:: set_size_limit(size_limit: int) -> None Sets the cache size limit in bytes. :param size_limit: the cache limit in bytes .. method:: store_tile_async(x: int, y: int, zoom_level: int, bytes: ~gi.repository.GLib.Bytes, etag: str | None = None, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Stores a tile in the cache. :param x: the X coordinate of the tile :param y: the Y coordinate of the tile :param zoom_level: the zoom level of the tile :param bytes: a :obj:`~gi.repository.GLib.Bytes` :param etag: an ETag string, or :const:`None` :param cancellable: a :obj:`~gi.repository.Gio.Cancellable` :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to execute upon completion :param user_data: closure data for ``callback`` .. method:: store_tile_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Gets the success value of a completed :func:`~gi.repository.Shumate.FileCache.store_tile_async` operation. :param result: a :obj:`~gi.repository.Gio.AsyncResult` provided to callback Properties ---------- .. rst-class:: interim-class .. class:: FileCache :no-index: .. attribute:: props.cache_dir :type: str The type of the None singleton. .. attribute:: props.cache_key :type: str The type of the None singleton. .. attribute:: props.size_limit :type: int The type of the None singleton.