Implement a (dumb) cache garbage collector.
[bluesky.git] / bluesky / cache.c
index 2c1bc92..50c0f36 100644 (file)
@@ -163,6 +163,24 @@ static void drop_caches(BlueSkyInode *inode)
 {
     if (inode->type == BLUESKY_REGULAR)
         bluesky_file_drop_cached(inode);
+
+    BlueSkyCloudLog *log = inode->committed_item;
+    if (log != NULL) {
+        g_mutex_lock(log->lock);
+        if (log->data != NULL
+            && g_atomic_int_get(&log->data_lock_count) == 0
+            && (log->location_flags != 0))
+        {
+            bluesky_cloudlog_stats_update(log, -1);
+            bluesky_string_unref(log->data);
+            log->data = NULL;
+            bluesky_cloudlog_stats_update(log, 1);
+        }
+        if (log->location_flags & CLOUDLOG_CLOUD) {
+            log->location_flags &= ~CLOUDLOG_JOURNAL;
+        }
+        g_mutex_unlock(log->lock);
+    }
 }
 
 /* Drop clean data from the cache if needed.  Clean data should generally be
@@ -225,6 +243,7 @@ static gpointer flushd_task(BlueSkyFS *fs)
     flushd_dirty(fs);
     flushd_cloud(fs);
     flushd_clean(fs);
+    bluesky_cachefile_gc(fs);
     g_mutex_unlock(fs->flushd_lock);
 
     return NULL;