Documentation ¶
Overview ¶
Package caching provides an easy to make a cache on top of the gc package used to track idle resources in taskcluster-worker.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDisposableSizeNotSupported = gc.ErrDisposableSizeNotSupported
ErrDisposableSizeNotSupported should be returned from DiskSize() and MemorySize() if said feature is not supported
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
A Cache is an object that wraps a constructor and manages the life-cycle of objects. At creation a cache is given a Constructor, a ResourceTracker and the option of being an exclusive or shared-cache, meaning if resources may be re-used before they are released.
func New ¶
func New(constructor Constructor, shared bool, tracker gc.ResourceTracker, monitor runtime.Monitor) *Cache
New returns a Cache wrapping constructor such that resources returned from Require are shared between all calls to Require with the same options, if shared is set to true. Otherwise, resources are exclusive.
func (*Cache) Purge ¶
Purge cached resources, notice that these resources may be in use. The filter function should return true if the resource should be purged, then it'll purged when it is no-longer in use.
func (*Cache) PurgeAll ¶
PurgeAll will purge all resources returning the first error, then proceeding and purging everything else, before returning the first error, if any.
func (*Cache) Require ¶
Require returns a resource for the given options
If the Cache is exclusive the resource will not be re-used before it is returned with a call to Release(resource). If the cache is shared the cache will only every create one instance of the resource, unless purged or freed by the ResourceTracker.
type Constructor ¶
A Constructor is function that given options creates a resource.
Notice, options must be JSON serializable, as they will be hashed to determine resource equivalence.