[gnome-builder/wip/clang-cache] egg-task-cache: allow overwriting previously cached entry
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/clang-cache] egg-task-cache: allow overwriting previously cached entry
- Date: Wed, 13 May 2015 05:27:58 +0000 (UTC)
commit 9a281eb381d91f8995897397bb47959a6ed6379b
Author: Christian Hergert <christian hergert me>
Date: Tue May 12 22:25:47 2015 -0700
egg-task-cache: allow overwriting previously cached entry
This allows us to continue dispatching cached results, and then replace
the cached value when the new value is available.
contrib/egg/egg-task-cache.c | 6 +++++-
contrib/egg/egg-task-cache.h | 1 +
tests/test-egg-cache.c | 2 +-
3 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/contrib/egg/egg-task-cache.c b/contrib/egg/egg-task-cache.c
index 608160f..a5adad1 100644
--- a/contrib/egg/egg-task-cache.c
+++ b/contrib/egg/egg-task-cache.c
@@ -315,6 +315,9 @@ egg_task_cache_populate (EggTaskCache *self,
g_assert (EGG_IS_TASK_CACHE (self));
g_assert (G_IS_OBJECT (value));
+ if (g_hash_table_contains (self->cache, key))
+ egg_task_cache_evict (self, key);
+
item = cache_item_new (self->key_copy_func ((gpointer)key),
g_object_ref (value),
self->time_to_live_usec);
@@ -396,6 +399,7 @@ egg_task_cache_fetch_cb (GObject *object,
void
egg_task_cache_get_async (EggTaskCache *self,
gconstpointer key,
+ gboolean force_update,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -412,7 +416,7 @@ egg_task_cache_get_async (EggTaskCache *self,
/*
* If we have the answer, return it now.
*/
- if ((ret = egg_task_cache_peek (self, key)))
+ if (!force_update && (ret = egg_task_cache_peek (self, key)))
{
g_task_return_pointer (task, g_object_ref (ret), g_object_unref);
return;
diff --git a/contrib/egg/egg-task-cache.h b/contrib/egg/egg-task-cache.h
index 4f0c587..10824e9 100644
--- a/contrib/egg/egg-task-cache.h
+++ b/contrib/egg/egg-task-cache.h
@@ -59,6 +59,7 @@ EggTaskCache *egg_task_cache_new (GHashFunc key_hash_func,
GDestroyNotify populate_callback_data_destroy);
void egg_task_cache_get_async (EggTaskCache *self,
gconstpointer key,
+ gboolean force_update,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
diff --git a/tests/test-egg-cache.c b/tests/test-egg-cache.c
index a2e7327..4c72e8d 100644
--- a/tests/test-egg-cache.c
+++ b/tests/test-egg-cache.c
@@ -48,7 +48,7 @@ test_task_cache (void)
g_assert (!egg_task_cache_peek (cache, "foo"));
g_assert (!egg_task_cache_evict (cache, "foo"));
- egg_task_cache_get_async (cache, "foo", NULL, get_foo_cb, NULL);
+ egg_task_cache_get_async (cache, "foo", TRUE, NULL, get_foo_cb, NULL);
g_main_loop_run (main_loop);
g_main_loop_unref (main_loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]