Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cigale
CIGALE
Commits
38747f50
Commit
38747f50
authored
Jun 30, 2013
by
Yannick Roehlly
Browse files
Implement module caching in the warehouse
parent
05d6c303
Changes
1
Hide whitespace changes
Inline
Side-by-side
pcigale/warehouse/__init__.py
View file @
38747f50
...
...
@@ -33,6 +33,37 @@ class SedWarehouse(object):
self
.
storage
=
SedStore
()
# Cache for modules
self
.
module_cache
=
{}
def
get_module_cached
(
self
,
name
,
**
kwargs
):
"""Get the SED module using the internal cache.
Parameters
----------
name : string
Module name.
The other keyworded parameters are the module parameters.
Returns
-------
a pcigale.sed.modules.Module instance
"""
# JSon representation of the tuple (name, parameters) used as a key
# for storing the module in the cache.
encoder
=
JSONEncoder
()
module_key
=
encoder
.
encode
((
name
,
kwargs
))
if
module_key
in
self
.
module_cache
:
module
=
self
.
module_cache
[
module_key
]
else
:
module
=
sed_modules
.
get_module
(
name
,
**
kwargs
)
self
.
module_cache
[
module_key
]
=
module
return
module
def
get_sed
(
self
,
module_list
,
parameter_list
):
"""Get the SED corresponding to the module and parameter lists
...
...
@@ -66,7 +97,7 @@ class SedWarehouse(object):
sed
=
self
.
storage
.
get
(
sed_key
)
if
not
sed
:
mod
=
se
d_modules
.
get_module
(
module_list
.
pop
(),
mod
=
se
lf
.
get_module
_cached
(
module_list
.
pop
(),
**
parameter_list
.
pop
())
if
(
len
(
module_list
)
==
0
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment