netsnmp_cache_handler.3
上传用户:wxp200602
上传日期:2007-10-30
资源大小:4028k
文件大小:15k
源码类别:
SNMP编程
开发平台:
Unix_Linux
- .TH "cache_handler: Maintains a cache of data for use by lower level handlers." 3 "28 Nov 2005" "Version 5.2.1.rc3" "net-snmp" " -*- nroff -*-
- .ad l
- .nh
- .SH NAME
- cache_handler: Maintains a cache of data for use by lower level handlers. - This helper checks to see whether the data has been loaded 'recently' (according to the timeout for that particular cache) and calls the registered 'load_cache' routine if necessary.
- .PP
- .SS "Functions"
- .in +1c
- .ti -1c
- .RI "fBnetsnmp_cachefP * fBnetsnmp_cache_get_headfP (void)"
- .br
- .RI "fIget cache head fP"
- .ti -1c
- .RI "fBnetsnmp_cachefP * fBnetsnmp_cache_find_by_oidfP (oid *rootoid, int rootoid_len)"
- .br
- .RI "fIfind existing cache fP"
- .ti -1c
- .RI "fBnetsnmp_cachefP * fBnetsnmp_cache_createfP (int timeout, NetsnmpCacheLoad *load_hook, NetsnmpCacheFree *free_hook, oid *rootoid, int rootoid_len)"
- .br
- .RI "fIreturns a cache fP"
- .ti -1c
- .RI "unsigned int fBnetsnmp_cache_timer_startfP (fBnetsnmp_cachefP *cache)"
- .br
- .RI "fIstarts the recurring cache_load callback fP"
- .ti -1c
- .RI "void fBnetsnmp_cache_timer_stopfP (fBnetsnmp_cachefP *cache)"
- .br
- .RI "fIstops the recurring cache_load callback fP"
- .ti -1c
- .RI "fBnetsnmp_mib_handlerfP * fBnetsnmp_cache_handler_getfP (fBnetsnmp_cachefP *cache)"
- .br
- .RI "fIreturns a cache handler that can be injected into a given handler chain. fP"
- .ti -1c
- .RI "fBnetsnmp_mib_handlerfP * fBnetsnmp_get_cache_handlerfP (int timeout, NetsnmpCacheLoad *load_hook, NetsnmpCacheFree *free_hook, oid *rootoid, int rootoid_len)"
- .br
- .RI "fIreturns a cache handler that can be injected into a given handler chain. fP"
- .ti -1c
- .RI "int fBnetsnmp_cache_handler_registerfP (fBnetsnmp_handler_registrationfP *reginfo, fBnetsnmp_cachefP *cache)"
- .br
- .RI "fIfunctionally the same as calling fBnetsnmp_register_handler()fP but also injects a cache handler at the same time for you. fP"
- .ti -1c
- .RI "int fBnetsnmp_register_cache_handlerfP (fBnetsnmp_handler_registrationfP *reginfo, int timeout, NetsnmpCacheLoad *load_hook, NetsnmpCacheFree *free_hook)"
- .br
- .RI "fIfunctionally the same as calling fBnetsnmp_register_handler()fP but also injects a cache handler at the same time for you. fP"
- .ti -1c
- .RI "NETSNMP_STATIC_INLINE char * fB_build_cache_namefP (const char *name)"
- .br
- .ti -1c
- .RI "void fBnetsnmp_cache_reqinfo_insertfP (fBnetsnmp_cachefP *cache, fBnetsnmp_agent_request_infofP *reqinfo, const char *name)"
- .br
- .RI "fIInsert the cache information for a given request (PDU). fP"
- .ti -1c
- .RI "fBnetsnmp_cachefP * fBnetsnmp_cache_reqinfo_extractfP (fBnetsnmp_agent_request_infofP *reqinfo, const char *name)"
- .br
- .RI "fIExtract the cache information for a given request (PDU). fP"
- .ti -1c
- .RI "fBnetsnmp_cachefP * fBnetsnmp_extract_cache_infofP (fBnetsnmp_agent_request_infofP *reqinfo)"
- .br
- .RI "fIExtract the cache information for a given request (PDU). fP"
- .ti -1c
- .RI "int fBnetsnmp_cache_check_expiredfP (fBnetsnmp_cachefP *cache)"
- .br
- .RI "fICheck if the cache timeout has passed. fP"
- .ti -1c
- .RI "int fBnetsnmp_cache_check_and_reloadfP (fBnetsnmp_cachefP *cache)"
- .br
- .RI "fIReload the cache if required. fP"
- .ti -1c
- .RI "int fBnetsnmp_cache_is_validfP (fBnetsnmp_agent_request_infofP *reqinfo, const char *name)"
- .br
- .RI "fIIs the cache valid for a given request? fP"
- .ti -1c
- .RI "int fBnetsnmp_is_cache_validfP (fBnetsnmp_agent_request_infofP *reqinfo)"
- .br
- .RI "fIfor backwards compat fP"
- .ti -1c
- .RI "int fBnetsnmp_cache_helper_handlerfP (fBnetsnmp_mib_handlerfP *handler, fBnetsnmp_handler_registrationfP *reginfo, fBnetsnmp_agent_request_infofP *reqinfo, fBnetsnmp_request_infofP *requests)"
- .br
- .RI "fIImplements the cache handler. fP"
- .ti -1c
- .RI "void fBrelease_cached_resourcesfP (unsigned int regNo, void *clientargs)"
- .br
- .RI "fIrun regularly to automatically release cached resources. fP"
- .in -1c
- .SH "Detailed Description"
- .PP
- This helper checks to see whether the data has been loaded 'recently' (according to the timeout for that particular cache) and calls the registered 'load_cache' routine if necessary.
- .PP
- The lower handlers can then work with this local cached data.
- .PP
- A timeout value of -1 will cause fBnetsnmp_cache_check_expired()fP to always return true, and thus the cache will be reloaded for every request.
- .PP
- To minimze resource use by the agent, a periodic callback checks for expired caches, and will call the free_cache function for any expired cache.
- .PP
- The load_cache route should return a negative number if the cache was not successfully loaded. 0 or any positive number indicates successs.
- .PP
- Several flags can be set to affect the operations on the cache.
- .PP
- If NETSNMP_CACHE_DONT_INVALIDATE_ON_SET is set, the free_cache method will not be called after a set request has processed. It is assumed that the lower mib handler using the cache has maintained cache consistency.
- .PP
- If NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD is set, the free_cache method will not be called before the load_cache method is called. It is assumed that the load_cache routine will properly deal with being called with a valid cache.
- .PP
- If NETSNMP_CACHE_DONT_FREE_EXPIRED is set, the free_cache method will not be called with the cache expires. The expired flag will be set, but the valid flag will not be cleared. It is assumed that the load_cache routine will properly deal with being called with a valid cache.
- .PP
- If NETSNMP_CACHE_PRELOAD is set when a the cache handler is created, the cache load routine will be called immediately.
- .PP
- If NETSNMP_CACHE_DONT_AUTO_RELEASE is set, the periodic callback that checks for expired caches will skip the cache. The cache will only be checked for expiration when a request triggers the cache handler. This is useful if the cache has it's own periodic callback to keep the cache fresh.
- .PP
- If NETSNMP_CACHE_AUTO_RELOAD is set, a timer will be set up to reload the cache when it expires. This is useful for keeping the cache fresh, even in the absence of incoming snmp requests.
- .PP
- Here are some suggestions for some common situations.
- .PP
- Cached File: If your table is based on a file that may periodically change, you can test the modification date to see if the file has changed since the last cache load. To get the cache helper to call the load function for every request, set the timeout to -1, which will cause the cache to always report that it is expired. This means that you will want to prevent the agent from flushing the cache when it has expired, and you will have to flush it manually if you detect that the file has changed. To accomplish this, set the following flags:
- .PP
- NETSNMP_CACHE_DONT_FREE_EXPIRED NETSNMP_CACHE_DONT_AUTO_RELEASE
- .PP
- Constant (periodic) reload: If you want the cache kept up to date regularly, even if no requests for the table are received, you can have your cache load routine called periodically. This is very useful if you need to monitor the data for changes (eg a fILastChangedfP object). You will need to prevent the agent from flushing the cache when it expires. Set the cache timeout to the frequency, in seconds, that you wish to reload your cache, and set the following flags:
- .PP
- NETSNMP_CACHE_DONT_FREE_EXPIRED NETSNMP_CACHE_DONT_AUTO_RELEASE NETSNMP_CACHE_AUTO_RELOAD
- .SH "Function Documentation"
- .PP
- .SS "int netsnmp_cache_check_and_reload (fBnetsnmp_cachefP * cache)"
- .PP
- Reload the cache if required.
- .PP
- Definition at line 382 of file cache_handler.c.
- .PP
- References netsnmp_cache_check_expired(), and netsnmp_cache_s::valid.
- .PP
- Referenced by netsnmp_cache_helper_handler().
- .SS "int netsnmp_cache_check_expired (fBnetsnmp_cachefP * cache)"
- .PP
- Check if the cache timeout has passed.
- .PP
- Sets and return the expired flag.
- .PP
- Definition at line 367 of file cache_handler.c.
- .PP
- References atime_ready(), netsnmp_cache_s::expired, NULL, netsnmp_cache_s::timeout, netsnmp_cache_s::timestamp, and netsnmp_cache_s::valid.
- .PP
- Referenced by netsnmp_cache_check_and_reload(), and release_cached_resources().
- .SS "fBnetsnmp_cachefP* netsnmp_cache_create (int timeout, NetsnmpCacheLoad * load_hook, NetsnmpCacheFree * free_hook, oid * rootoid, int rootoid_len)"
- .PP
- returns a cache
- .PP
- Definition at line 139 of file cache_handler.c.
- .PP
- References netsnmp_cache_s::enabled, netsnmp_cache_s::free_cache, netsnmp_cache_s::load_cache, netsnmp_ds_get_int(), netsnmp_cache_s::next, NULL, netsnmp_cache_s::prev, netsnmp_cache_s::rootoid, netsnmp_cache_s::rootoid_len, snmp_duplicate_objid(), snmp_log(), SNMP_MALLOC_TYPEDEF, and netsnmp_cache_s::timeout.
- .PP
- Referenced by netsnmp_get_cache_handler().
- .SS "fBnetsnmp_cachefP* netsnmp_cache_find_by_oid (oid * rootoid, int rootoid_len)"
- .PP
- find existing cache
- .PP
- Definition at line 123 of file cache_handler.c.
- .PP
- References netsnmp_oid_equals(), netsnmp_cache_s::next, NULL, netsnmp_cache_s::rootoid, and netsnmp_cache_s::rootoid_len.
- .SS "fBnetsnmp_cachefP* netsnmp_cache_get_head (void)"
- .PP
- get cache head
- .PP
- Definition at line 115 of file cache_handler.c.
- .SS "fBnetsnmp_mib_handlerfP* netsnmp_cache_handler_get (fBnetsnmp_cachefP * cache)"
- .PP
- returns a cache handler that can be injected into a given handler chain.
- .PP
- Definition at line 244 of file cache_handler.c.
- .PP
- References netsnmp_mib_handler_s::flags, netsnmp_cache_s::flags, MIB_HANDLER_AUTO_NEXT, netsnmp_mib_handler_s::myvoid, netsnmp_cache_helper_handler(), netsnmp_cache_timer_start(), netsnmp_create_handler(), NULL, and netsnmp_cache_s::valid.
- .PP
- Referenced by netsnmp_cache_handler_register(), and netsnmp_get_cache_handler().
- .SS "int netsnmp_cache_handler_register (fBnetsnmp_handler_registrationfP * reginfo, fBnetsnmp_cachefP * cache)"
- .PP
- functionally the same as calling fBnetsnmp_register_handler()fP but also injects a cache handler at the same time for you.
- .PP
- Definition at line 292 of file cache_handler.c.
- .PP
- References netsnmp_cache_handler_get(), netsnmp_inject_handler(), netsnmp_register_handler(), and NULL.
- .SS "int netsnmp_cache_helper_handler (fBnetsnmp_mib_handlerfP * handler, fBnetsnmp_handler_registrationfP * reginfo, fBnetsnmp_agent_request_infofP * reqinfo, fBnetsnmp_request_infofP * requests)"
- .PP
- Implements the cache handler.
- .PP
- next handler called automatically - 'AUTO_NEXT'
- .PP
- next handler called automatically - 'AUTO_NEXT'
- .PP
- next handler called automatically - 'AUTO_NEXT'
- .PP
- Definition at line 417 of file cache_handler.c.
- .PP
- References netsnmp_cache_s::cache_hint, netsnmp_cache_s::enabled, netsnmp_cache_s::flags, netsnmp_mib_handler_s::flags, netsnmp_cache_s::free_cache, netsnmp_handler_args_s::handler, netsnmp_handler_registration_s::handlerName, netsnmp_cache_s::load_cache, netsnmp_cache_s::magic, MIB_HANDLER_AUTO_NEXT, netsnmp_agent_request_info_s::mode, netsnmp_mib_handler_s::myvoid, netsnmp_cache_check_and_reload(), netsnmp_cache_is_valid(), netsnmp_cache_reqinfo_insert(), netsnmp_ds_get_boolean(), netsnmp_set_all_requests_error(), NULL, netsnmp_handler_args_s::reginfo, netsnmp_handler_args_s::reqinfo, netsnmp_handler_args_s::requests, netsnmp_handler_registration_s::rootoid, netsnmp_handler_registration_s::rootoid_len, snmp_log(), and netsnmp_cache_s::valid.
- .PP
- Referenced by netsnmp_cache_handler_get().
- .SS "int netsnmp_cache_is_valid (fBnetsnmp_agent_request_infofP * reqinfo, const char * name)"
- .PP
- Is the cache valid for a given request?
- .PP
- Definition at line 399 of file cache_handler.c.
- .PP
- References netsnmp_cache_reqinfo_extract(), and netsnmp_cache_s::valid.
- .PP
- Referenced by netsnmp_cache_helper_handler(), and netsnmp_is_cache_valid().
- .SS "fBnetsnmp_cachefP* netsnmp_cache_reqinfo_extract (fBnetsnmp_agent_request_infofP * reqinfo, const char * name)"
- .PP
- Extract the cache information for a given request (PDU).
- .PP
- Definition at line 347 of file cache_handler.c.
- .PP
- References _build_cache_name(), netsnmp_agent_get_list_data(), and SNMP_FREE.
- .PP
- Referenced by netsnmp_cache_is_valid(), and netsnmp_extract_cache_info().
- .SS "void netsnmp_cache_reqinfo_insert (fBnetsnmp_cachefP * cache, fBnetsnmp_agent_request_infofP * reqinfo, const char * name)"
- .PP
- Insert the cache information for a given request (PDU).
- .PP
- Definition at line 330 of file cache_handler.c.
- .PP
- References _build_cache_name(), netsnmp_agent_add_list_data(), netsnmp_agent_get_list_data(), netsnmp_create_data_list(), NULL, and SNMP_FREE.
- .PP
- Referenced by netsnmp_cache_helper_handler().
- .SS "unsigned int netsnmp_cache_timer_start (fBnetsnmp_cachefP * cache)"
- .PP
- starts the recurring cache_load callback
- .PP
- Definition at line 194 of file cache_handler.c.
- .PP
- References netsnmp_cache_s::flags, NULL, snmp_alarm_register(), snmp_log(), netsnmp_cache_s::timeout, and netsnmp_cache_s::timer_id.
- .PP
- Referenced by netsnmp_cache_handler_get().
- .SS "void netsnmp_cache_timer_stop (fBnetsnmp_cachefP * cache)"
- .PP
- stops the recurring cache_load callback
- .PP
- Definition at line 224 of file cache_handler.c.
- .PP
- References NULL, snmp_alarm_unregister(), snmp_log(), and netsnmp_cache_s::timer_id.
- .SS "fBnetsnmp_cachefP* netsnmp_extract_cache_info (fBnetsnmp_agent_request_infofP * reqinfo)"
- .PP
- Extract the cache information for a given request (PDU).
- .PP
- Definition at line 359 of file cache_handler.c.
- .PP
- References netsnmp_cache_reqinfo_extract().
- .SS "fBnetsnmp_mib_handlerfP* netsnmp_get_cache_handler (int timeout, NetsnmpCacheLoad * load_hook, NetsnmpCacheFree * free_hook, oid * rootoid, int rootoid_len)"
- .PP
- returns a cache handler that can be injected into a given handler chain.
- .PP
- Definition at line 273 of file cache_handler.c.
- .PP
- References netsnmp_mib_handler_s::myvoid, netsnmp_cache_create(), netsnmp_cache_handler_get(), and NULL.
- .PP
- Referenced by netsnmp_register_cache_handler().
- .SS "int netsnmp_is_cache_valid (fBnetsnmp_agent_request_infofP * reqinfo)"
- .PP
- for backwards compat
- .PP
- fBnetsnmp_cache_is_valid()fP is preferred.
- .PP
- Definition at line 410 of file cache_handler.c.
- .PP
- References netsnmp_cache_is_valid().
- .SS "int netsnmp_register_cache_handler (fBnetsnmp_handler_registrationfP * reginfo, int timeout, NetsnmpCacheLoad * load_hook, NetsnmpCacheFree * free_hook)"
- .PP
- functionally the same as calling fBnetsnmp_register_handler()fP but also injects a cache handler at the same time for you.
- .PP
- Definition at line 305 of file cache_handler.c.
- .PP
- References netsnmp_get_cache_handler(), netsnmp_inject_handler(), netsnmp_register_handler(), NULL, netsnmp_handler_registration_s::rootoid, and netsnmp_handler_registration_s::rootoid_len.
- .SS "void release_cached_resources (unsigned int regNo, void * clientargs)"
- .PP
- run regularly to automatically release cached resources.
- .PP
- xxx - method to prevent cache from expiring while a request is being processed (e.g. delegated request). proposal: set a flag, which would be cleared when request finished (which could be acomplished by a dummy data list item in agent req info & custom free function).
- .PP
- Definition at line 574 of file cache_handler.c.
- .PP
- References netsnmp_cache_s::flags, netsnmp_cache_check_expired(), netsnmp_cache_s::next, NULL, snmp_alarm_register(), and netsnmp_cache_s::valid.