[PATCH 02/13] cache: Create persistent named cache



Add API to create a persistent cache with a user-provided name.

Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>
---
 src/grl-media-cache.c |   24 ++++++++++++++++++++++++
 src/grl-media-cache.h |    2 ++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/grl-media-cache.c b/src/grl-media-cache.c
index c210d97..37bd213 100644
--- a/src/grl-media-cache.c
+++ b/src/grl-media-cache.c
@@ -308,6 +308,30 @@ grl_media_cache_new (void)
   return cache;
 }
 
+GrlMediaCache *
+grl_media_cache_new_persistent (const gchar *cache_id)
+{
+  GrlMediaCache *cache = NULL;
+  sqlite3 *db;
+
+  g_return_val_if_fail (cache_id, NULL);
+
+  GRL_DEBUG (__FUNCTION__);
+
+  /* Create the cache */
+  db = create_table (cache_id);
+
+  if (db) {
+    cache = g_object_new (GRL_TYPE_MEDIA_CACHE,
+                          "cache-id", cache_id,
+                          "persistent", TRUE,
+                          NULL);
+    cache->priv->db = db;
+  }
+
+  return cache;
+}
+
 gboolean
 grl_media_cache_insert_media (GrlMediaCache *cache,
                               GrlMedia *media,
diff --git a/src/grl-media-cache.h b/src/grl-media-cache.h
index 6b427d5..a4affc1 100644
--- a/src/grl-media-cache.h
+++ b/src/grl-media-cache.h
@@ -90,6 +90,8 @@ GType grl_media_cache_get_type (void);
 
 GrlMediaCache *grl_media_cache_new (void);
 
+GrlMediaCache *grl_media_cache_new_persistent (const gchar *cache_id);
+
 gboolean grl_media_cache_insert_media (GrlMediaCache *cache,
                                        GrlMedia *media,
                                        const gchar *parent,
-- 
1.7.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]