requires could be apply to a slave and properties could be different
This commit is contained in:
@ -29,8 +29,11 @@ configurator ``set_storage()``.
|
||||
from time import time
|
||||
from random import randint
|
||||
import os
|
||||
from tiramisu.error import ConfigError
|
||||
from tiramisu.i18n import _
|
||||
from ..error import ConfigError
|
||||
from ..i18n import _
|
||||
|
||||
|
||||
MODULE_PATH = os.path.split(os.path.split(os.path.split(__file__)[0])[0])[1]
|
||||
|
||||
|
||||
class StorageType(object):
|
||||
@ -53,7 +56,7 @@ class StorageType(object):
|
||||
if self.storage_type is None:
|
||||
self.storage_type = self.default_storage
|
||||
if self.mod is None:
|
||||
modulepath = 'tiramisu.storage.{0}'.format(self.storage_type)
|
||||
modulepath = '{0}.storage.{1}'.format(MODULE_PATH, self.storage_type)
|
||||
try:
|
||||
mod = __import__(modulepath)
|
||||
except ImportError:
|
||||
|
@ -17,9 +17,9 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# ____________________________________________________________
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu.setting import undefined
|
||||
from tiramisu.error import ConfigError
|
||||
from ...i18n import _
|
||||
from ...setting import undefined
|
||||
from ...error import ConfigError
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
|
@ -14,8 +14,8 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ____________________________________________________________
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu.error import ConfigError
|
||||
from ...i18n import _
|
||||
from ...error import ConfigError
|
||||
from ..util import SerializeObject
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ____________________________________________________________
|
||||
from ..util import Cache
|
||||
from tiramisu.setting import undefined
|
||||
from ...setting import undefined
|
||||
|
||||
|
||||
class Values(Cache):
|
||||
|
@ -15,7 +15,7 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ____________________________________________________________
|
||||
from tiramisu.setting import owners
|
||||
from ..setting import owners
|
||||
|
||||
|
||||
class SerializeObject(object):
|
||||
@ -97,27 +97,30 @@ class Cache(object):
|
||||
value = tuple(_value)
|
||||
setattr(self, key, value)
|
||||
|
||||
def setcache(self, path, val, time):
|
||||
self._cache[path] = (val, time)
|
||||
def setcache(self, path, val, time, index):
|
||||
self._cache.setdefault(path, {})[index] = (val, time)
|
||||
|
||||
def getcache(self, path, exp):
|
||||
value, created = self._cache[path]
|
||||
def getcache(self, path, exp, index):
|
||||
value, created = self._cache[path][index]
|
||||
if created is None or exp <= created:
|
||||
return True, value
|
||||
return False, None
|
||||
|
||||
def hascache(self, path):
|
||||
def hascache(self, path, index):
|
||||
""" path is in the cache
|
||||
|
||||
:param path: the path's option
|
||||
"""
|
||||
return path in self._cache
|
||||
return path in self._cache and index in self._cache[path]
|
||||
|
||||
def reset_expired_cache(self, exp):
|
||||
for key in tuple(self._cache.keys()):
|
||||
val, created = self._cache[key]
|
||||
if created is not None and exp > created:
|
||||
del(self._cache[key])
|
||||
for key in self._cache.keys():
|
||||
for index in self._cache[key].keys():
|
||||
val, created = self._cache[key][index]
|
||||
if created is not None and exp > created:
|
||||
del(self._cache[key][index])
|
||||
if self._cache[key] == {}:
|
||||
del(self._cache[key])
|
||||
|
||||
def reset_all_cache(self):
|
||||
"empty the cache"
|
||||
@ -125,6 +128,6 @@ class Cache(object):
|
||||
|
||||
def get_cached(self, context):
|
||||
"""return all values in a dictionary
|
||||
example: {'path1': ('value1', 'time1'), 'path2': ('value2', 'time2')}
|
||||
example: {'path1': {'index1': ('value1', 'time1')}, 'path2': {'index2': ('value2', 'time2', )}}
|
||||
"""
|
||||
return self._cache
|
||||
|
Reference in New Issue
Block a user