comparison 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
comparison
equal deleted inserted replaced
114:628697fdfcbd 115:c8ca47a67bf3
300 pimpl_->db_.Execute("CREATE TABLE Cache(seq INTEGER PRIMARY KEY, bundle INTEGER, item TEXT, fileUuid TEXT, fileSize INT);"); 300 pimpl_->db_.Execute("CREATE TABLE Cache(seq INTEGER PRIMARY KEY, bundle INTEGER, item TEXT, fileUuid TEXT, fileSize INT);");
301 pimpl_->db_.Execute("CREATE INDEX CacheBundles ON Cache(bundle);"); 301 pimpl_->db_.Execute("CREATE INDEX CacheBundles ON Cache(bundle);");
302 pimpl_->db_.Execute("CREATE INDEX CacheIndex ON Cache(bundle, item);"); 302 pimpl_->db_.Execute("CREATE INDEX CacheIndex ON Cache(bundle, item);");
303 } 303 }
304 304
305 if (!pimpl_->db_.DoesTableExist("CacheProperties"))
306 {
307 printf("ICI\n");
308 pimpl_->db_.Execute("CREATE TABLE CacheProperties(property INTEGER PRIMARY KEY, value TEXT);");
309 }
310
305 // Performance tuning of SQLite with PRAGMAs 311 // Performance tuning of SQLite with PRAGMAs
306 // http://www.sqlite.org/pragma.html 312 // http://www.sqlite.org/pragma.html
307 pimpl_->db_.Execute("PRAGMA SYNCHRONOUS=OFF;"); 313 pimpl_->db_.Execute("PRAGMA SYNCHRONOUS=OFF;");
308 pimpl_->db_.Execute("PRAGMA JOURNAL_MODE=WAL;"); 314 pimpl_->db_.Execute("PRAGMA JOURNAL_MODE=WAL;");
309 pimpl_->db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;"); 315 pimpl_->db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;");
587 t.Run(); 593 t.Run();
588 594
589 ReadBundleStatistics(); 595 ReadBundleStatistics();
590 SanityCheck(); 596 SanityCheck();
591 } 597 }
598
599
600 void CacheManager::SetProperty(CacheProperty property,
601 const std::string& value)
602 {
603 Orthanc::SQLite::Statement s(pimpl_->db_, SQLITE_FROM_HERE,
604 "INSERT OR REPLACE INTO CacheProperties VALUES(?, ?)");
605 s.BindInt(0, property);
606 s.BindString(1, value);
607 s.Run();
608 }
609
610
611 bool CacheManager::LookupProperty(std::string& target,
612 CacheProperty property)
613 {
614 Orthanc::SQLite::Statement s(pimpl_->db_, SQLITE_FROM_HERE,
615 "SELECT value FROM CacheProperties WHERE property=?");
616 s.BindInt(0, property);
617
618 if (!s.Step())
619 {
620 return false;
621 }
622 else
623 {
624 target = s.ColumnString(0);
625 return true;
626 }
627 }
592 } 628 }