+/*
+ *-------------------------------------------------------------------
+ * long-term cache - keep keywords from whole dir in memory
+ *-------------------------------------------------------------------
+ */
+
+/* fd->cached metadata list of lists
+ each particular list contains key as a first entry, then the values
+*/
+
+static void metadata_cache_update(FileData *fd, const gchar *key, const GList *values)
+{
+ GList *work;
+
+ work = fd->cached_metadata;
+ while (work)
+ {
+ GList *entry = work->data;
+ gchar *entry_key = entry->data;
+
+ if (strcmp(entry_key, key) == 0)
+ {
+ /* key found - just replace values */
+ GList *old_values = entry->next;
+ entry->next = NULL;
+ old_values->prev = NULL;
+ string_list_free(old_values);
+ work->data = g_list_append(entry, string_list_copy(values));
+ DEBUG_1("updated %s %s\n", key, fd->path);
+ return;
+ }
+ work = work->next;
+ }
+
+ /* key not found - prepend new entry */
+ fd->cached_metadata = g_list_prepend(fd->cached_metadata,
+ g_list_prepend(string_list_copy(values), g_strdup(key)));
+ DEBUG_1("added %s %s\n", key, fd->path);
+
+}
+
+static const GList *metadata_cache_get(FileData *fd, const gchar *key)
+{
+ GList *work;
+
+ work = fd->cached_metadata;
+ while (work)
+ {
+ GList *entry = work->data;
+ gchar *entry_key = entry->data;
+
+ if (strcmp(entry_key, key) == 0)
+ {
+ /* key found */
+ DEBUG_1("found %s %s\n", key, fd->path);
+ return entry;
+ }
+ work = work->next;
+ }
+ return NULL;
+ DEBUG_1("not found %s %s\n", key, fd->path);
+}
+
+static void metadata_cache_remove(FileData *fd, const gchar *key)
+{
+ GList *work;
+
+ work = fd->cached_metadata;
+ while (work)
+ {
+ GList *entry = work->data;
+ gchar *entry_key = entry->data;
+
+ if (strcmp(entry_key, key) == 0)
+ {
+ /* key found */
+ string_list_free(entry);
+ fd->cached_metadata = g_list_delete_link(fd->cached_metadata, work);
+ DEBUG_1("removed %s %s\n", key, fd->path);
+ return;
+ }
+ work = work->next;
+ }
+ DEBUG_1("not removed %s %s\n", key, fd->path);
+}
+
+void metadata_cache_free(FileData *fd)
+{
+ GList *work;
+ if (fd->cached_metadata) DEBUG_1("freed %s\n", fd->path);
+
+ work = fd->cached_metadata;
+ while (work)
+ {
+ GList *entry = work->data;
+ string_list_free(entry);
+
+ work = work->next;
+ }
+ g_list_free(fd->cached_metadata);
+ fd->cached_metadata = NULL;
+}
+
+
+
+
+