[gnome-software/gnome-3-22] trivial: Add gs_plugin_cache_remove()



commit 290dd171eae4aa9c8a1409ab9af724987db29169
Author: Richard Hughes <richard hughsie com>
Date:   Mon Oct 31 14:42:33 2016 +0000

    trivial: Add gs_plugin_cache_remove()
    
    This allows plugins to remove items from the cache.
    
    (cherry picked from commit 781a28dc3d53581725af6bb4218d24f129c4d837)

 src/gs-plugin.c |   33 +++++++++++++++++++++++++++++++++
 src/gs-plugin.h |    2 ++
 2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 37ef7bb..235a00b 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -47,6 +47,7 @@
 #include <gio/gdesktopappinfo.h>
 #include <gdk/gdk.h>
 
+#include "gs-app-list-private.h"
 #include "gs-os-release.h"
 #include "gs-plugin-private.h"
 #include "gs-plugin.h"
@@ -1208,6 +1209,38 @@ gs_plugin_cache_lookup (GsPlugin *plugin, const gchar *key)
 }
 
 /**
+ * gs_plugin_cache_remove:
+ * @plugin: a #GsPlugin
+ * @key: a key which matches
+ *
+ * Removes an application from the per-plugin cache.
+ *
+ * Since: 3.24
+ **/
+void
+gs_plugin_cache_remove (GsPlugin *plugin, const gchar *key)
+{
+       GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+
+       g_return_if_fail (GS_IS_PLUGIN (plugin));
+       g_return_if_fail (key != NULL);
+
+       /* global, so using internal unique_id */
+       if (gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_GLOBAL_CACHE)) {
+               GsApp *app_tmp;
+               if (!as_utils_unique_id_valid (key)) {
+                       g_critical ("key %s is not a unique_id", key);
+                       return;
+               }
+               app_tmp = gs_app_list_lookup (priv->global_cache, key);
+               if (app_tmp != NULL)
+                       gs_app_list_remove (priv->global_cache, app_tmp);
+               return;
+       }
+       g_hash_table_remove (priv->cache, key);
+}
+
+/**
  * gs_plugin_cache_add:
  * @plugin: a #GsPlugin
  * @key: a string, or %NULL if the unique ID should be used
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 7cceeda..0dfa8e7 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -293,6 +293,8 @@ GsApp               *gs_plugin_cache_lookup                 (GsPlugin       *plugin,
 void            gs_plugin_cache_add                    (GsPlugin       *plugin,
                                                         const gchar    *key,
                                                         GsApp          *app);
+void            gs_plugin_cache_remove                 (GsPlugin       *plugin,
+                                                        const gchar    *key);
 void            gs_plugin_cache_invalidate             (GsPlugin       *plugin);
 void            gs_plugin_status_update                (GsPlugin       *plugin,
                                                         GsApp          *app,


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