]> granicus.if.org Git - apache/blobdiff - include/ap_socache.h
mod_cache: Add the cache_status hook to register the final cache
[apache] / include / ap_socache.h
index 8d0492e34db26acc5979414e7300c565d9b63859..e00c316f6d79a4968f3b2f3b4c980eaa645fef3f 100644 (file)
 #include "httpd.h"
 #include "ap_provider.h"
 #include "apr_pools.h"
+#include "apr_time.h"
 
-/** If this flag is set, the store/retrieve/delete/status interfaces
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** If this flag is set, the store/retrieve/remove/status interfaces
  * of the provider are NOT safe to be called concurrently from
  * multiple processes or threads, and an external global mutex must be
- * used to serialize access to the provider. */
+ * used to serialize access to the provider.
+ */
+/* XXX: Even if store/retrieve/remove is atomic, isn't it useful to note
+ * independently that status and iterate may or may not be?
+ */
 #define AP_SOCACHE_FLAG_NOTMPSAFE (0x0001)
 
 /** A cache instance. */
@@ -46,11 +55,34 @@ struct ap_socache_hints {
     apr_size_t avg_id_len;
     /** Approximate average size of objects: */
     apr_size_t avg_obj_size;
-    /** Interval (in seconds) after which an expiry run is
-     * necessary. */
-    time_t expiry_interval;
+    /** Suggested interval between expiry cleanup runs; */
+    apr_interval_time_t expiry_interval;
 };
 
+/**
+ * Iterator callback prototype for the ap_socache_provider_t->iterate() method
+ * @param instance The cache instance
+ * @param s Associated server context (for logging)
+ * @param userctx User defined pointer passed from the iterator call
+ * @param id Unique ID for the object (binary blob)
+ * with a trailing null char for convenience
+ * @param idlen Length of id blob
+ * @param data Output buffer to place retrieved data (binary blob)
+ * with a trailing null char for convenience
+ * @param datalen Length of data buffer
+ * @param pool Pool for temporary allocations
+ * @return APR status value; return APR_SUCCESS or the iteration will halt;
+ * this value is returned to the ap_socache_provider_t->iterate() caller
+ */
+typedef apr_status_t (ap_socache_iterator_t)(ap_socache_instance_t *instance,
+                                             server_rec *s,
+                                             void *userctx,
+                                             const unsigned char *id,
+                                             unsigned int idlen,
+                                             const unsigned char *data,
+                                             unsigned int datalen,
+                                             apr_pool_t *pool);
+
 /** A socache provider structure.  socache providers are registered
  * with the ap_provider.h interface using the AP_SOCACHE_PROVIDER_*
  * constants. */
@@ -112,11 +144,14 @@ typedef struct ap_socache_provider_t {
      * @param expiry Absolute time at which the object expires
      * @param data Data to store; binary blob
      * @param datalen Length of data blob
+     * @param pool Pool for temporary allocations.
+     * @return APR status value.
      */
     apr_status_t (*store)(ap_socache_instance_t *instance, server_rec *s, 
                           const unsigned char *id, unsigned int idlen, 
-                          time_t expiry, 
-                          unsigned char *data, unsigned int datalen);
+                          apr_time_t expiry, 
+                          unsigned char *data, unsigned int datalen,
+                          apr_pool_t *pool);
 
     /**
      * Retrieve a cached object.
@@ -128,6 +163,8 @@ typedef struct ap_socache_provider_t {
      * @param datalen On entry, length of data buffer; on exit, the
      * number of bytes written to the data buffer.
      * @param pool Pool for temporary allocations.
+     * @return APR status value; APR_NOTFOUND if the object was not
+     * found
      */
     apr_status_t (*retrieve)(ap_socache_instance_t *instance, server_rec *s,
                              const unsigned char *id, unsigned int idlen,
@@ -141,18 +178,35 @@ typedef struct ap_socache_provider_t {
      * @param idlen Length of id blob
      * @param pool Pool for temporary allocations.
      */
-    void (*delete)(ap_socache_instance_t *instance, server_rec *s,
-                   const unsigned char *id, unsigned int idlen,
-                   apr_pool_t *pool);
+    apr_status_t (*remove)(ap_socache_instance_t *instance, server_rec *s,
+                           const unsigned char *id, unsigned int idlen,
+                           apr_pool_t *pool);
 
     /** Dump the status of a cache instance for mod_status.  Will use
      * the ap_r* interfaces to produce appropriate status output.
+     * XXX: ap_r* are deprecated, bad dogfood
      *
      * @param instance The cache instance
      * @param r The request structure
      * @param flags The AP_STATUS_* constants used (see mod_status.h)
      */
     void (*status)(ap_socache_instance_t *instance, request_rec *r, int flags);
+
+    /**
+     * Dump all cached objects through an iterator callback.
+     * @param instance The cache instance
+     * @param s Associated server context (for processing and logging)
+     * @param userctx User defined pointer passed through to the iterator
+     * @param iterator The user provided callback function which will receive
+     * individual calls for each unexpired id/data pair
+     * @param pool Pool for temporary allocations.
+     * @return APR status value; APR_NOTFOUND if the object was not
+     * found
+     */
+    apr_status_t (*iterate)(ap_socache_instance_t *instance, server_rec *s,
+                            void *userctx, ap_socache_iterator_t *iterator,
+                            apr_pool_t *pool);
+
 } ap_socache_provider_t;
 
 /** The provider group used to register socache providers. */
@@ -163,5 +217,9 @@ typedef struct ap_socache_provider_t {
 /** Default provider name. */
 #define AP_SOCACHE_DEFAULT_PROVIDER "default"
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* AP_SOCACHE_H */
 /** @} */