Caching and Cache-consuming Snippets

Download this manual as a PDF file

Configuration and performance Snippet Dynamic Applications can:

  • Cache a single object that can be pickled. To cache an object, a configuration or performance Snippet Dynamic Application must have Cache Results selected in the Caching drop-down list in the Dynamic Applications Properties Editor. The cached object can be used by other configuration or performance Snippet Dynamic Applications that have Consume Cached Results selected in the Caching drop-down list in the Dynamic Applications Properties Editor.
  • Use the cached results from one or more requests or snippets in Dynamic Applications that have Cache Results selected in the Caching drop-down list in the Dynamic Applications Properties Editor. To use the cached results from other Dynamic Applications, a configuration or performance Snippet Dynamic Application must have Consume Cached Results selected in the Caching drop-down list in the Dynamic Applications Properties Editor. Each snippet can consume one cached result. Unlike other Dynamic Application types that can consume cached results:
    • Snippet Dynamic Applications can consume any type of cached result.
    • The snippets defined in Snippet Dynamic Applications that consume cached results are not limited to using only the contents of the cached response. When you configure a Snippet Dynamic Application to consume cached results, your snippet code can still perform other collection and data processing in addition to using the cached response.

For more information about caching, see the section on caching for all Dynamic Application types.

Use the following menu options to navigate the SL1 user interface:

  • To view a pop-out list of menu options, click the menu icon ().
  • To view a page containing all of the menu options, click the Advanced menu icon ().

Caching a Result in a Snippet

When a Snippet Dynamic Application is configured to Cache Results, you can use the following global function to cache an object:

em7_cache_result(object)

 

When you cache an object using the em7_cache_result() function:

  • The em7_cache_result() function takes a single argument. You should pass the single object that you want to cache.
  • SL1 will pickle the passed object before the object is stored. Python must be able to pickle the object you pass to the em7_cache_result() function. Do not pickle the object in your snippet code before passing it to the em7_cache_result() function.

NOTE: Remember, the collection objects defined in a Dynamic Application that caches its results are no longer collected at a regular frequency. You must not define collection objects that are used to generate configuration tables or performance graphs in a Dynamic Application that caches results. Typically, Dynamic Applications that cache results will contain only a discovery object.

Using a Cached Result in a Snippet

When a Snippet Dynamic Application is configured to Consume Cached Results, the Cached object drop-down list appears in the Dynamic Applications Snippet Editor & Registry (Snippets tab) for that Dynamic Application.

The Cached object drop-down list will contain all requests defined for Dynamic Applications that have Cache Results selected in the Caching drop-down list in the Dynamic Applications Properties Editor. Select the cached result you want to use in your snippet code.

Remember, the Dynamic Application that populates the cache must be aligned to the same device (or for component devices, the root device) as the Dynamic Application that consumes the cache.

When a request is selected in the Cached object drop-down list, the variable EM7_CACHED_OBJECT will be available to the snippet code. The EM7_CACHED_OBJECT variable will contain the cached result. The structure of EM7_CACHED_OBJECT is different based on the type of cached result:

  • For results cached by Snippet Dynamic Applications, the contents of EM7_CACHED_OBJECT is the object that was cached using the em7_cache_result() function. SL1 will automatically unpickle the object; you do not need to unpickle the object in your snippet code.
  • For results cached by SOAP, XML, and XSLT Dynamic Applications, the contents of EM7_CACHED_OBJECT is the returned XML document. For XSLT Dynamic Applications, the XML document is the response from the device before the transformation is applied.
  • For results cached by WMI Dynamic Applications, EM7_CACHED_OBJECT is a dictionary of values:
    • The keys in the EM7_CACHED_OBJECT dictionary are the property names (columns) from the response.
    • For convenience, each property has two keys in the EM7_CACHED_OBJECT dictionary: one is the unmodified property name, one is the property name converted to all lowercase. The values associated with the unmodified and lowercase keys will be identical for the same property name.
    • Each value in the dictionary is a list of values returned for that property. The key for each value in the list is the corresponding WMI Object Key value.