diff Plugin/Cache/CacheManager.cpp @ 115:c8ca47a67bf3

automatic clearing of the cache
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Dec 2015 17:08:51 +0100
parents a6492d20b2a8
children 3dc81012e76a
line wrap: on
line diff
--- a/Plugin/Cache/CacheManager.cpp	Mon Dec 07 16:19:22 2015 +0100
+++ b/Plugin/Cache/CacheManager.cpp	Mon Dec 07 17:08:51 2015 +0100
@@ -302,6 +302,12 @@
       pimpl_->db_.Execute("CREATE INDEX CacheIndex ON Cache(bundle, item);");
     }
 
+    if (!pimpl_->db_.DoesTableExist("CacheProperties"))
+    {
+      printf("ICI\n");
+      pimpl_->db_.Execute("CREATE TABLE CacheProperties(property INTEGER PRIMARY KEY, value TEXT);");
+    }
+
     // Performance tuning of SQLite with PRAGMAs
     // http://www.sqlite.org/pragma.html
     pimpl_->db_.Execute("PRAGMA SYNCHRONOUS=OFF;");
@@ -589,4 +595,34 @@
     ReadBundleStatistics();
     SanityCheck();
   }
+
+
+  void CacheManager::SetProperty(CacheProperty property,
+                                 const std::string& value)
+  {
+    Orthanc::SQLite::Statement s(pimpl_->db_, SQLITE_FROM_HERE,
+                                 "INSERT OR REPLACE INTO CacheProperties VALUES(?, ?)");
+    s.BindInt(0, property);
+    s.BindString(1, value);
+    s.Run();
+  }
+
+
+  bool CacheManager::LookupProperty(std::string& target,
+                                    CacheProperty property)
+  {
+    Orthanc::SQLite::Statement s(pimpl_->db_, SQLITE_FROM_HERE, 
+                                 "SELECT value FROM CacheProperties WHERE property=?");
+    s.BindInt(0, property);
+
+    if (!s.Step())
+    {
+      return false;
+    }
+    else
+    {
+      target = s.ColumnString(0);
+      return true;
+    }
+  }
 }