Shumate.FileCache

g GObject.Object GObject.Object Shumate.FileCache Shumate.FileCache GObject.Object->Shumate.FileCache

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new_full (size_limit, cache_key, cache_dir)

get_cache_dir ()

get_cache_key ()

get_size_limit ()

get_tile_async (x, y, zoom_level, cancellable, callback, *user_data)

get_tile_finish (result)

mark_up_to_date (x, y, zoom_level)

purge_cache_async (cancellable, callback, *user_data)

purge_cache_finish (result)

set_size_limit (size_limit)

store_tile_async (x, y, zoom_level, bytes, etag, cancellable, callback, *user_data)

store_tile_finish (result)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

cache-dir

str

r/w/co

The directory of the cache

cache-key

str

r/w/co

The key used when storing and retrieving tiles

size-limit

int

r/w/c

The cache’s size limit (Mb)

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Shumate.FileCache(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Shumate.FileCacheClass

A cache that stores and retrieves tiles from the file system. It is mainly used by [class`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).

classmethod new_full(size_limit, cache_key, cache_dir)
Parameters:
  • size_limit (int) – maximum size of the cache in bytes

  • cache_key (str) – an ID for the tileset to store/retrieve

  • cache_dir (str or None) – the directory where the cache is created. When cache_dir == None, a cache in ~/.cache/shumate is used.

Returns:

a constructed Shumate.FileCache

Return type:

Shumate.FileCache

Constructor of Shumate.FileCache.

get_cache_dir()
Returns:

the directory

Return type:

str

Gets the directory where the cache database is stored.

get_cache_key()
Returns:

the cache key

Return type:

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.

get_size_limit()
Returns:

size limit

Return type:

int

Gets the cache size limit in bytes.

get_tile_async(x, y, zoom_level, cancellable, callback, *user_data)
Parameters:

Gets tile data from the cache, if it is available.

get_tile_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult provided to callback

Raises:

GLib.Error

Returns:

a GLib.Bytes containing the tile data, or None if the tile was not in the cache or an error occurred

etag:

a location for the data’s ETag, or None

modtime:

a location to return the tile’s last modification time, or None

Return type:

(GLib.Bytes, etag: str or None, modtime: GLib.DateTime or None)

Gets the tile data from a completed 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.

mark_up_to_date(x, y, zoom_level)
Parameters:
  • x (int) – the X coordinate of the tile

  • y (int) – the Y coordinate of the tile

  • zoom_level (int) – the zoom level of the tile

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.

purge_cache_async(cancellable, callback, *user_data)
Parameters:

Removes less used tiles from the cache, if necessary, until it fits in the size limit.

purge_cache_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult provided to callback

Raises:

GLib.Error

Returns:

True if any tiles were removed, otherwise False

Return type:

bool

Gets the result of an async operation started using Shumate.FileCache.purge_cache_async().

set_size_limit(size_limit)
Parameters:

size_limit (int) – the cache limit in bytes

Sets the cache size limit in bytes.

store_tile_async(x, y, zoom_level, bytes, etag, cancellable, callback, *user_data)
Parameters:

Stores a tile in the cache.

store_tile_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult provided to callback

Raises:

GLib.Error

Returns:

True if the operation was successful, otherwise False

Return type:

bool

Gets the success value of a completed Shumate.FileCache.store_tile_async() operation.

Property Details

Shumate.FileCache.props.cache_dir
Name:

cache-dir

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The directory where the tile database is stored.

Shumate.FileCache.props.cache_key
Name:

cache-key

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

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.

Shumate.FileCache.props.size_limit
Name:

size-limit

Type:

int

Default Value:

100000000

Flags:

READABLE, WRITABLE, CONSTRUCT

The cache size limit in bytes.

Note: this new value will not be applied until you call shumate_file_cache_purge()