= cockpit.js: Object CachingIf the same information is displayed by multiple components in Cockpit,`+cockpit.cache()+` provides a way to share data between them. Theshared data should be simple objects, arrays, and values, and notcontain functions or other objects.[[cockpit-cache-func]]== cockpit.cache()....cache = cockpit.cache(key, provider, consumer)....Create a new cache object. The `+key+` should be a globally uniquestring that describes the data being cached. This string must describethe data, across all machines and all versions of cockpit. It iscustomary to include a version number in the `+key+` string.....function provider(result, key) {result("myvalue");return {close: function() {/* closed */}};}....The `+provider+` is a function that will be invoked to start retrievingdata for the cache. It will be passed a `+result+` function as its firstargument. The `+result+` should be invoked whenever new data isavailable. The `+key+` argument matches the key string the cache wascreated with.The `+provider+` can return an object with a `+close+` method. Thismethod will be invoked when the cache no longer needs data from theprovider.....function consumer(value, key) {/* ... */}....The `+consumer+` is a function that will be passed new values when theyare available, whether they come from the `+provider+` or a source in adifferent component/frame.[[cockpit-cache-close]]== cache.close()....cache.close()....Close a cache and stop calling its `+consumer+`. If the `+provider+` wasinvoked, then the `+close()+` method it returned will be invoked.