Difference between revisions of "Cache handler"
From Net-SNMP Wiki
(Created page with "{{helper|Cache Handler|documentation=cache__handler|code=agent/helpers/cache_helper.c}} == Overview == The cache_helper is designed to do one thing: help you manage a cache of ...") |
(starting at example code.) |
||
Line 7: | Line 7: | ||
It is typically injected during the mib module's initialization routine. | It is typically injected during the mib module's initialization routine. | ||
− | == | + | == Usage == |
− | + | Using the cache handler involves a few steps: | |
+ | |||
+ | # inject a cache handler into the handler chain for your module | ||
+ | # implement the loading routine | ||
+ | # implement the free routine | ||
+ | # use the cache to load your data | ||
+ | |||
+ | === Initialization === | ||
+ | |||
+ | In your init_XXX() routine, do something like this: | ||
+ | |||
+ | #define MY_CACHE_TIMEOUT 30 | ||
+ | |||
+ | NetsnmpCacheLoad *my_cache_load; | ||
+ | NetsnmpCacheFree *my_cache_free; | ||
+ | |||
+ | struct my_cache { | ||
+ | int index; | ||
+ | char *value; | ||
+ | }; | ||
+ | |||
+ | void init_XXX() { | ||
+ | netsnmp_mib_handler *cache_handler; | ||
+ | |||
+ | /* create and register your "object". Example using the ... */ | ||
+ | netsnmp_register_table_iterator(reginfo, iterator_info); | ||
+ | |||
+ | /* now create our cache handler: */ | ||
+ | cache_handler = netsnmp_get_cache_handler(MY_CACHE_TIMEOUT, /* how long a cache is valid for */ | ||
+ | my_cache_Sload, /* a pointer to the cache loading function */ | ||
+ | my_cahe_free, /* a pointer to the cache freeing function */ | ||
+ | my_oid, OID_LENGTH(my_oid))); /* the OID of the registration point */ | ||
+ | |||
+ | /* Inject the handler into the handler chain for our registration: */ | ||
+ | netsnmp_inject_handler(reginfo, cache_handler); | ||
+ | } | ||
+ | |||
+ | === Loading === |
Revision as of 16:29, 14 July 2011
Net-SNMP MIB Helper | |
Cache Handler | |
Documentation: | doxygen API |
---|---|
Code: | agent/helpers/cache_helper.c |
Other Helpers: | Agent Helpers |
Contents
Overview
The cache_helper is designed to do one thing: help you manage a cache of data for a given mib implementation. It simply calls your load and free hooks based on how long the cache should remain valid. You define the data structures to hold the information and use your cache to respond to requests. The cache handler simply takes care of the timing about when to load it.
It is typically injected during the mib module's initialization routine.
Usage
Using the cache handler involves a few steps:
- inject a cache handler into the handler chain for your module
- implement the loading routine
- implement the free routine
- use the cache to load your data
Initialization
In your init_XXX() routine, do something like this:
#define MY_CACHE_TIMEOUT 30 NetsnmpCacheLoad *my_cache_load; NetsnmpCacheFree *my_cache_free;
struct my_cache { int index; char *value; }; void init_XXX() { netsnmp_mib_handler *cache_handler;
/* create and register your "object". Example using the ... */ netsnmp_register_table_iterator(reginfo, iterator_info); /* now create our cache handler: */ cache_handler = netsnmp_get_cache_handler(MY_CACHE_TIMEOUT, /* how long a cache is valid for */
my_cache_Sload, /* a pointer to the cache loading function */
my_cahe_free, /* a pointer to the cache freeing function */
my_oid, OID_LENGTH(my_oid))); /* the OID of the registration point */
/* Inject the handler into the handler chain for our registration: */ netsnmp_inject_handler(reginfo, cache_handler); }