Skip to content

pk: Set cache-age hint in the RefreshCache transaction

Alessandro Astone requested to merge aleasto/discover:pk-refresh into master

This was originally introduced in Fedora by Rex Dieter. My lenghty explaination follows.

PackageKit has two ways of getting caches refreshed, one is through the RefreshCache(bool force) transaction and the other is through the SetHints('cache-age=%d') method before starting a transaction that would use the cache. When the cache-age hint is unset, it is defined to mean that the cache should not be expired no matter how old it is.

Backends are not required to honour the cache-age hint.

For backends that implement the cache-age, the RefreshCache(false) transaction will only refresh cache if the specified cache-age hint suggests that the available cache is too old. RefreshCache(true) will instead ignore the cache-age hint. However the intended way to use the cache-age is to never call RefreshCache and directly set the cache-age hint in the PackageKit transactions that do stuff.

Backends that ignore the cache-age hint will instead always refresh the cache regardless of the bool force parameter of RefresCache. The force parameter is totally ignored.

This is arguably poorly designed in PackageKit as it forces clients like Discover to think about the behaviour of different backends.

The PackageKit backend in Discover was thought against the apt backend, that does not implement a cache-age and thus relies on manually calling RefreshCache periodically. This is a perfectly valid mode of operation even for backends that instead implement a cache-age, but on those backends calling RefreshCache(false) without setting the cache-age hint is a noop!

Because calling RefreshCache(true) or RefreshCache(false) is exactly equivalent in backends that do not honour cache-age hints, this change allows Discover to work on backends that do honour the cache-age hint without affecting the others.

The dnf backend implements the cache-age hint. For RefreshCache to do anything, we need to change the cache-age from the default - MAX_UINT32 - to a low amount.

The minimum amount supported by PackageKit is "1 second", meaning that the backend will redownload the caches if they are more than 1 second old.

Edited by Alessandro Astone

Merge request reports