Back to index

texmacs  1.0.7.15
Functions
data_cache.hpp File Reference
#include "url.hpp"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void cache_set (string buffer, tree key, tree im)
void cache_reset (string buffer, tree key)
bool is_cached (string buffer, tree key)
tree cache_get (string buffer, tree key)
bool is_up_to_date (url dir, bool reset=false)
bool is_recursively_up_to_date (url dir)
bool do_cache_dir (string name)
bool do_cache_stat_fail (string name)
bool do_cache_stat (string name)
bool do_cache_file (string name)
bool do_cache_doc (string name)
void cache_save (string buffer)
void cache_load (string buffer)
void cache_memorize ()
void cache_refresh ()
void cache_initialize ()

Function Documentation

tree cache_get ( string  buffer,
tree  key 
)

Definition at line 49 of file data_cache.cpp.

                                    {
  tree ckey= tuple (buffer, key);
  return cache_data [ckey];
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cache_initialize ( )

Definition at line 230 of file data_cache.cpp.

                    {
  texmacs_path= url_system ("$TEXMACS_PATH");
  if (get_env ("TEXMACS_HOME_PATH") == "")
    texmacs_home_path= url_system ("$HOME/.TeXmacs");
  else texmacs_home_path= url_system ("$TEXMACS_HOME_PATH");
  if (get_env ("TEXMACS_DOC_PATH") == "")
    texmacs_doc_path= url_system ("$TEXMACS_PATH/doc");
  else texmacs_doc_path= url_system ("$TEXMACS_DOC_PATH");
  
  texmacs_path_string = concretize (texmacs_path);
  texmacs_home_path_string = concretize (texmacs_home_path);
  texmacs_doc_path_string = concretize (texmacs_doc_path);
  texmacs_font_path_string = concretize (texmacs_home_path * "fonts/");
  
   
  cache_refresh ();
  if (is_recursively_up_to_date (texmacs_path * "fonts/type1") &&
      is_recursively_up_to_date (texmacs_path * "fonts/truetype") &&
      is_recursively_up_to_date (texmacs_home_path * "fonts/type1") &&
      is_recursively_up_to_date (texmacs_home_path * "fonts/truetype"));
  else remove (texmacs_home_path * "fonts/error" * url_wildcard ("*"));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cache_load ( string  buffer)

Definition at line 173 of file data_cache.cpp.

                           {
  if (!cache_loaded->contains (buffer)) {
    url cache_file = texmacs_home_path * url ("system/cache/" * buffer);
    //cout << "cache_file "<< cache_file << LF;
    string cached;
    if (!load_string (cache_file, cached, false)) {
      if (buffer == "file_cache" || buffer == "doc_cache") {
       int i=0, n= N(cached);
       while (i<n) {
         int start= i;
         while (i<n && cached[i] != '\n') i++;
         string key= cached (start, i);
         i++; start= i;
         while (i<n && (cached[i] != '\n' ||
                      !test (cached, i+1, "%-%-tm-cache-%-%"))) i++;
         string im= cached (start, i);
         i++;
         while (i<n && cached[i] != '\n') i++;
         i++;
         //cout << "key= " << key << "\n----------------------\n";
         //cout << "im= " << im << "\n----------------------\n";
         cache_data (tuple (buffer, key))= im;
       }
      }
      else {
       tree t= scheme_to_tree (cached);
       for (int i=0; i<N(t)-1; i+=2)
         cache_data (tuple (buffer, t[i]))= t[i+1];
      }
    }
    cache_loaded->insert (buffer);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cache_memorize ( )

Definition at line 208 of file data_cache.cpp.

                  {
  cache_save ("file_cache");
  cache_save ("doc_cache");
  cache_save ("dir_cache.scm");
  cache_save ("stat_cache.scm");
  cache_save ("font_cache.scm");
  cache_save ("validate_cache.scm");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cache_refresh ( )

Definition at line 218 of file data_cache.cpp.

                 {
  cache_data   = hashmap<tree,tree> ("?");
  cache_loaded = hashset<string> ();
  cache_changed= hashset<string> ();
  cache_load ("file_cache");
  cache_load ("dir_cache.scm");
  cache_load ("stat_cache.scm");
  cache_load ("font_cache.scm");
  cache_load ("validate_cache.scm");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cache_reset ( string  buffer,
tree  key 
)

Definition at line 36 of file data_cache.cpp.

                                      {
  tree ckey= tuple (buffer, key);
  cache_data->reset (ckey);
  cache_changed->insert (buffer);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cache_save ( string  buffer)

Definition at line 141 of file data_cache.cpp.

                           {
  if (cache_changed->contains (buffer)) {
    url cache_file= texmacs_home_path * url ("system/cache/" * buffer);
    string cached;
    iterator<tree> it= iterate (cache_data);
    if (buffer == "file_cache" || buffer == "doc_cache") {
      while (it->busy ()) {
       tree ckey= it->next ();
       if (ckey[0] == buffer) {
         cached << ckey[1]->label << "\n";
         cached << cache_data [ckey]->label << "\n";
         cached << "%-%-tm-cache-%-%\n";
       }
      }
    }
    else {
      cached << "(tuple\n";
      while (it->busy ()) {
       tree ckey= it->next ();
       if (ckey[0] == buffer) {
         cached << tree_to_scheme (ckey[1]) << " ";
         cached << tree_to_scheme (cache_data [ckey]) << "\n";
       }
      }
      cached << ")";
    }
    (void) save_string (cache_file, cached);
    cache_changed->remove (buffer);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cache_set ( string  buffer,
tree  key,
tree  im 
)

Definition at line 27 of file data_cache.cpp.

                                            {
  tree ckey= tuple (buffer, key);
  if (cache_data[ckey] != t) {
    cache_data (ckey)= t;
    cache_changed->insert (buffer);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool do_cache_dir ( string  name)

Definition at line 101 of file data_cache.cpp.

                           {
  return
    starts (name, texmacs_path_string) ||
    starts (name, texmacs_doc_path_string);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool do_cache_doc ( string  name)

Definition at line 132 of file data_cache.cpp.

                           {
  return starts (name, texmacs_doc_path_string);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool do_cache_file ( string  name)

Definition at line 124 of file data_cache.cpp.

                            {
  return
    !ends (name, ".ts") &&
    (starts (name, texmacs_path_string) ||
     starts (name, texmacs_font_path_string));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool do_cache_stat ( string  name)

Definition at line 108 of file data_cache.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool do_cache_stat_fail ( string  name)

Definition at line 116 of file data_cache.cpp.

                                 {
  return
    !ends (name, ".ts") &&
    (starts (name, texmacs_path_string) ||
     starts (name, texmacs_doc_path_string));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_cached ( string  buffer,
tree  key 
)

Definition at line 43 of file data_cache.cpp.

                                    {
  tree ckey= tuple (buffer, key);
  return cache_data->contains (ckey);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 75 of file data_cache.cpp.

                                    {
  if (!is_up_to_date (dir)) return false;
  bool error_flag;
  array<string> a= read_directory (dir, error_flag);
  for (int i=0; i<N(a); i++)
    if (url (a[i]) != url_here () && url (a[i]) != url_parent ())
      if (is_directory (dir * a[i]))
       if (!is_recursively_up_to_date (dir * a[i]))
         return false;
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_up_to_date ( url  dir,
bool  reset = false 
)

Definition at line 55 of file data_cache.cpp.

                                    {
  string name_dir= concretize (dir);
  if (reset) cache_valid->reset (name_dir);
  if (cache_valid->contains (name_dir)) return cache_valid [name_dir];
  int l= last_modified (dir, false);
  if (is_cached ("validate_cache.scm", name_dir)) {
    int r= as_int (cache_get ("validate_cache.scm", name_dir) -> label);
    if (l == r) {
      cache_valid (name_dir)= true;
      return true;
    }
    //cout << name_dir << " no longer up to date " << r << " -> " << l << "\n";
  }
  //else cout << name_dir << " not up to date " << l << "\n";
  cache_set ("validate_cache.scm", name_dir, as_string (l));
  cache_valid (name_dir)= false;
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function: