The dr_cache_refresh function provides a way of refreshing a cache entry when the plug-in requires it. This can be achieved by passing NULL for the ref parameter in dr_cache_init and by passing DR_CHECK in a dr_net_write call. If DR_CHECK is passed to dr_net_write and it returns with DR_EXPIR, the plug-in should generate new content in the entry and call dr_cache_refresh with that entry before calling dr_net_write again to send the response.
The plug-in may simply decide to replace the cached entry even if it has not expired (based on some other business logic). The dr_cache_refresh function is useful in this case. This way the plug-in does the cache refresh management actively by itself.
PRInt32 dr_cache_refresh(DrHdl hdl, const char *key, PRUint32 klen, PRIntervalTime timeout, Entry *entry, Request *rq, Session *sn);
1 if successful.
0 if an error occurs.
The following table describes parameters for the dr_cache_refresh function.
Table 11–2 dr_cache_refresh parameters
Parameter |
Description |
---|---|
DrHdl hdl |
Persistent handle created by the dr_cache_init function. |
const char *key |
Key to cache, search, or refresh. |
PRUint32 klen |
Length of the key in bytes. |
PRIntervalTime timeout |
Expiration time of this entry. If a value of 0 is passed, the maxAge value passed to dr_cache_init is used. |
Entry *entry |
The not NULL entry to be cached. |
Request *rq |
Pointer to the request. |
Session *sn |
Pointer to the session. |
Entry entry; char *key = "MOVIES" GenNewMovieList(&entry.data, &entry.dataLen); // Implemented by // plugin developer if(!dr_cache_refresh(hdl, key, strlen(key), 0, &entry, rq, sn)) { ereport(LOG_FAILURE, "dr_cache_refresh() failed"); return REQ_ABORTED; }