diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2011-03-01 11:22:17 -0800 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2011-03-01 11:22:17 -0800 |
commit | cf5c5f6a492bb92b25aeb880e46e9df2560a4c2e (patch) | |
tree | d809498d46d5141a78d29306ecdd4fccb0424142 /src | |
parent | 02226c41245c0c2fa2f4deb2e5b4ffdc0f34b84b (diff) | |
download | vyatta-cfg-cf5c5f6a492bb92b25aeb880e46e9df2560a4c2e.tar.gz vyatta-cfg-cf5c5f6a492bb92b25aeb880e46e9df2560a4c2e.zip |
add caching for parsed config templates
* this improves backend performance by ~15% in, e.g., "load" (w/o commit) and "show".
* this is only temporary and eventually caching should be done at higher level for better performance, and that will require config path abstraction.
Diffstat (limited to 'src')
-rw-r--r-- | src/cstore/unionfs/cstore-unionfs.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp index b42c8f8..50aefb5 100644 --- a/src/cstore/unionfs/cstore-unionfs.cpp +++ b/src/cstore/unionfs/cstore-unionfs.cpp @@ -415,18 +415,33 @@ UnionfsCstore::tmpl_node_exists() return (b_fs_exists(tmpl_path) && b_fs_is_directory(tmpl_path)); } +typedef Cstore::MapT<string, tr1::shared_ptr<vtw_def> > ParsedTmplCacheT; +static ParsedTmplCacheT _parsed_tmpl_cache; + /* parse template at current tmpl_path and return an allocated Ctemplate * pointer if successful. otherwise return 0. */ Ctemplate * UnionfsCstore::tmpl_parse() { + b_fs::path tp = tmpl_path / C_DEF_NAME; + if (!b_fs_exists(tp) || !b_fs_is_regular(tp)) { + // invalid + return 0; + } + + ParsedTmplCacheT::iterator p = _parsed_tmpl_cache.find(tp.file_string()); + if (p != _parsed_tmpl_cache.end()) { + // found in cache + return (new Ctemplate(p->second)); + } + + // new template => parse tr1::shared_ptr<vtw_def> def(new vtw_def); vtw_def *_def = def.get(); - b_fs::path tp = tmpl_path / C_DEF_NAME; - if (_def && b_fs_exists(tp) && b_fs_is_regular(tp) - && parse_def(_def, tp.file_string().c_str(), 0) == 0) { - // succes + if (_def && parse_def(_def, tp.file_string().c_str(), 0) == 0) { + // succes => cache and return + _parsed_tmpl_cache[tp.file_string()] = def; return (new Ctemplate(def)); } return 0; |