public static TM_Xml_Database                    clear_GuidanceItemsCache(this TM_Xml_Database tmDatabase)
 {
     "[TM_Xml_Database] clear_GuidanceItemsCache".info();
     if (tmDatabase.UsingFileStorage)
     {
         var cacheFile = tmDatabase.getCacheLocation();
         if (cacheFile.notNull() && cacheFile.fileExists())
         {
             Files.deleteFile(cacheFile);
             "cache file deleted OK:{0}".info(cacheFile.fileExists().isFalse());
         }
     }
     tmDatabase.Cached_GuidanceItems.Clear();
     return(tmDatabase);
 }
 public static TM_Xml_Database                    save_GuidanceItemsToCache(this TM_Xml_Database tmDatabase)
 {
     if (tmDatabase.UsingFileStorage)
     {
         var cacheFile = tmDatabase.getCacheLocation();
         if (cacheFile.notNull())
         {
             var o2Timer = new O2Timer("saveGuidanceItemsToCache").start();
             lock (TM_Xml_Database.Current.Cached_GuidanceItems)
             {
                 TM_Xml_Database.Current.Cached_GuidanceItems.Values.toList().saveAs(cacheFile);
                 tmDatabase.triggerGitCommit();
             }
             o2Timer.stop();
         }
     }
     return(tmDatabase);
 }
        public static TM_Xml_Database                    load_GuidanceItemsFromCache(this TM_Xml_Database tmDatabase)
        {
            //"Loading items from cache".info();
            var chacheFile = tmDatabase.getCacheLocation();

            if (chacheFile.fileExists().isFalse())
            {
                "[TM_Xml_Database] in loadGuidanceItemsFromCache, cached file not found: {0}".error(chacheFile);
                tmDatabase.xmlDB_Load_GuidanceItems_and_Create_CacheFile();
            }
            else
            {
                var o2Timer             = new O2Timer("loadGuidanceItemsFromCache").start();
                var loadedGuidanceItems = chacheFile.load <List <TeamMentor_Article> >();
                o2Timer.stop();
                if (loadedGuidanceItems.isNull()) //if we couldn't load it , delete it
                {
                    Files.deleteFile(chacheFile);
                }
                else
                {
                    o2Timer = new O2Timer("mapping to memory loadGuidanceItemsFromCache").start();
                    foreach (var loadedGuidanceItem in loadedGuidanceItems)
                    {
                        if (loadedGuidanceItem.notNull())
                        {
                            TM_Xml_Database.Current.Cached_GuidanceItems.add(loadedGuidanceItem.Metadata.Id,
                                                                             loadedGuidanceItem);
                        }
                    }
                    o2Timer.stop();
                }
                tmDatabase.populateGuidanceItemsFileMappings();
            }
            return(tmDatabase);
        }