Trim trailing white spaces on empty lines.
[geeqie.git] / src / filecache.c
index d212ada..aa77acb 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Geeqie
- * Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: Vladimir Nadvornik
  *
@@ -32,6 +32,7 @@ struct _FileCacheEntry {
 };
 
 static void file_cache_notify_cb(FileData *fd, NotifyType type, gpointer data);
+static void file_cache_remove_fd(FileCacheData *fc, FileData *fd);
 
 FileCacheData *file_cache_new(FileCacheReleaseFunc release, gulong max_size)
 {
@@ -50,7 +51,7 @@ FileCacheData *file_cache_new(FileCacheReleaseFunc release, gulong max_size)
 gboolean file_cache_get(FileCacheData *fc, FileData *fd)
 {
        GList *work;
-       
+
        g_assert(fc && fd);
 
        work = fc->list;
@@ -60,22 +61,24 @@ gboolean file_cache_get(FileCacheData *fc, FileData *fd)
                if (fce->fd == fd)
                        {
                        /* entry exists */
-                       DEBUG_1("cache hit: fc=%p %s", fc, fd->path);
+                       DEBUG_2("cache hit: fc=%p %s", fc, fd->path);
                        if (work == fc->list) return TRUE; /* already at the beginning */
                        /* move it to the beginning */
-                       DEBUG_1("cache move to front: fc=%p %s", fc, fd->path);
+                       DEBUG_2("cache move to front: fc=%p %s", fc, fd->path);
                        fc->list = g_list_remove_link(fc->list, work);
                        fc->list = g_list_concat(work, fc->list);
-                       
-                       if (file_data_check_changed_files(fd)) /* this will eventually remove changed files from cache via file_cache_notify_cb */
+
+                       if (file_data_check_changed_files(fd)) {
+                               /* file has been changed, cance entry is no longer valid */
+                               file_cache_remove_fd(fc, fd);
                                return FALSE;
-                               
+                       }
                        if (debug_file_cache) file_cache_dump(fc);
                        return TRUE;
                        }
                work = work->next;
                }
-       DEBUG_1("cache miss: fc=%p %s", fc, fd->path);
+       DEBUG_2("cache miss: fc=%p %s", fc, fd->path);
        return FALSE;
 }
 
@@ -94,8 +97,8 @@ void file_cache_set_size(FileCacheData *fc, gulong size)
                prev = work->prev;
                fc->list = g_list_delete_link(fc->list, work);
                work = prev;
-               
-               DEBUG_1("file changed - cache remove: fc=%p %s", fc, last_fe->fd->path);
+
+               DEBUG_2("file changed - cache remove: fc=%p %s", fc, last_fe->fd->path);
                fc->size -= last_fe->size;
                fc->release(last_fe->fd);
                file_data_unref(last_fe->fd);
@@ -108,14 +111,14 @@ void file_cache_put(FileCacheData *fc, FileData *fd, gulong size)
        FileCacheEntry *fe;
 
        if (file_cache_get(fc, fd)) return;
-       
-       DEBUG_1("cache add: fc=%p %s", fc, fd->path);
+
+       DEBUG_2("cache add: fc=%p %s", fc, fd->path);
        fe = g_new(FileCacheEntry, 1);
        fe->fd = file_data_ref(fd);
        fe->size = size;
        fc->list = g_list_prepend(fc->list, fe);
        fc->size += size;
-       
+
        file_cache_set_size(fc, fc->max_size);
 }
 
@@ -152,7 +155,7 @@ static void file_cache_remove_fd(FileCacheData *fc, FileData *fd)
                if (fe->fd == fd)
                        {
                        fc->list = g_list_delete_link(fc->list, current);
-               
+
                        DEBUG_1("cache remove: fc=%p %s", fc, fe->fd->path);
                        fc->size -= fe->size;
                        fc->release(fe->fd);
@@ -168,7 +171,7 @@ void file_cache_dump(FileCacheData *fc)
        gulong n = 0;
 
        DEBUG_1("cache dump: fc=%p max size:%ld size:%ld", fc, fc->max_size, fc->size);
-               
+
        while (work)
                {
                FileCacheEntry *fe = work->data;
@@ -181,8 +184,9 @@ static void file_cache_notify_cb(FileData *fd, NotifyType type, gpointer data)
 {
        FileCacheData *fc = data;
 
-       if (type != NOTIFY_TYPE_INTERNAL) /* invalidate the entry on each file change */
+       if (type & (NOTIFY_REREAD | NOTIFY_CHANGE)) /* invalidate the entry on each file change */
                {
+               DEBUG_1("Notify cache: %s %04x", fd->path, type);
                file_cache_remove_fd(fc, fd);
                }
 }