[libsoup/cache] soup-cache: make the 'get-cacheability' function a virtual method
- From: Xan Lopez <xan src gnome org>
- To: svn-commits-list gnome org
- Subject: [libsoup/cache] soup-cache: make the 'get-cacheability' function a virtual method
- Date: Mon, 27 Jul 2009 11:57:14 +0000 (UTC)
commit 9b05ca319c7dc24b3be067add3a8e1319e89e60a
Author: Xan Lopez <xan gnome org>
Date: Mon Jul 27 14:55:57 2009 +0300
soup-cache: make the 'get-cacheability' function a virtual method
This way subclasses can override the default behaviour and decide, for
example, to serve non-fresh data in some situations.
libsoup/soup-cache.c | 29 +++++++++++++++++++++--------
libsoup/soup-cache.h | 23 +++++++++++++++++++----
2 files changed, 40 insertions(+), 12 deletions(-)
---
diff --git a/libsoup/soup-cache.c b/libsoup/soup-cache.c
index ef6208a..2072e9d 100644
--- a/libsoup/soup-cache.c
+++ b/libsoup/soup-cache.c
@@ -47,12 +47,6 @@ enum {
PROP_CACHE_DIR
};
-typedef enum {
- SOUP_CACHE_CACHEABLE = (1 << 0),
- SOUP_CACHE_UNCACHEABLE = (1 << 1),
- SOUP_CACHE_INVALIDATES = (1 << 2)
-} SoupCacheability;
-
#define SOUP_CACHE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUP_TYPE_CACHE, SoupCachePrivate))
G_DEFINE_TYPE_WITH_CODE (SoupCache, soup_cache, G_TYPE_OBJECT,
@@ -60,7 +54,7 @@ G_DEFINE_TYPE_WITH_CODE (SoupCache, soup_cache, G_TYPE_OBJECT,
soup_cache_session_feature_init))
static SoupCacheability
-get_cacheability (SoupMessage *msg)
+get_cacheability (SoupCache *cache, SoupMessage *msg)
{
SoupCacheability cacheability;
const char *cache_control;
@@ -467,7 +461,7 @@ msg_got_headers_cb (SoupMessage *msg, SoupCache *cache)
{
SoupCacheability cacheable;
- cacheable = get_cacheability (msg);
+ cacheable = soup_cache_get_cacheability (cache, msg);
if (cacheable & SOUP_CACHE_CACHEABLE) {
SoupCacheEntry *entry;
@@ -804,6 +798,8 @@ soup_cache_class_init (SoupCacheClass *cache_class)
gobject_class->set_property = soup_cache_set_property;
gobject_class->get_property = soup_cache_get_property;
+ cache_class->get_cacheability = get_cacheability;
+
g_object_class_install_property(gobject_class, PROP_CACHE_DIR,
g_param_spec_string("cache-dir",
"Cache directory",
@@ -832,3 +828,20 @@ soup_cache_new (const char *cache_dir)
NULL);
}
+/**
+ * soup_cache_get_cacheability:
+ * @cache: a #SoupCache
+ * @msg: a #SoupMessage
+ *
+ * Calculates whether the @msg can be cached or not.
+ *
+ * Returns: a #SoupCacheability value indicating whether the @msg can be cached or not.
+ **/
+SoupCacheability
+soup_cache_get_cacheability (SoupCache *cache, SoupMessage *msg)
+{
+ g_return_val_if_fail (SOUP_IS_CACHE (cache), SOUP_CACHE_UNCACHEABLE);
+ g_return_val_if_fail (SOUP_IS_MESSAGE (msg), SOUP_CACHE_UNCACHEABLE);
+
+ return SOUP_CACHE_GET_CLASS (cache)->get_cacheability (cache, msg);
+}
diff --git a/libsoup/soup-cache.h b/libsoup/soup-cache.h
index be3d7ca..6854466 100644
--- a/libsoup/soup-cache.h
+++ b/libsoup/soup-cache.h
@@ -19,6 +19,12 @@ G_BEGIN_DECLS
typedef struct _SoupCachePrivate SoupCachePrivate;
+typedef enum {
+ SOUP_CACHE_CACHEABLE = (1 << 0),
+ SOUP_CACHE_UNCACHEABLE = (1 << 1),
+ SOUP_CACHE_INVALIDATES = (1 << 2)
+} SoupCacheability;
+
struct _SoupCache {
GObject parent_instance;
@@ -28,16 +34,25 @@ struct _SoupCache {
typedef struct {
GObjectClass parent_class;
+ /* methods */
+ SoupCacheability (*get_cacheability) (SoupCache *cache, SoupMessage *msg);
+
/* Padding for future expansion */
void (*_libsoup_reserved1) (void);
void (*_libsoup_reserved2) (void);
void (*_libsoup_reserved3) (void);
} SoupCacheClass;
-GType soup_cache_get_type (void);
-SoupCache *soup_cache_new (const char *cache_dir);
-gboolean soup_cache_has_response (SoupCache *cache, SoupSession *session, SoupMessage *msg);
-void soup_cache_send_response (SoupCache *cache, SoupSession *session, SoupMessage *msg);
+GType soup_cache_get_type (void);
+SoupCache* soup_cache_new (const char *cache_dir);
+gboolean soup_cache_has_response (SoupCache *cache,
+ SoupSession *session,
+ SoupMessage *msg);
+void soup_cache_send_response (SoupCache *cache,
+ SoupSession *session,
+ SoupMessage *msg);
+SoupCacheability soup_cache_get_cacheability (SoupCache *cache,
+ SoupMessage *msg);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]