mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-30 02:40:08 +00:00
added selective flushing and more testing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e89aa0e9b9
commit
fafc050e45
24
index.py
24
index.py
@ -1,7 +1,7 @@
|
|||||||
#=======================================================================
|
#=======================================================================
|
||||||
|
|
||||||
__version__ = '''0.0.01'''
|
__version__ = '''0.0.01'''
|
||||||
__sub_version__ = '''20111208163546'''
|
__sub_version__ = '''20111208164549'''
|
||||||
__copyright__ = '''(c) Alex A. Naanou 2011'''
|
__copyright__ = '''(c) Alex A. Naanou 2011'''
|
||||||
|
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ def save_file_index(index, path, flat_index=False, ext='.json'):
|
|||||||
p = os.path.join(path, k + ext)
|
p = os.path.join(path, k + ext)
|
||||||
json.dump(v, file(p, 'w'), indent=4, separators=(', ', ': '))
|
json.dump(v, file(p, 'w'), indent=4, separators=(', ', ': '))
|
||||||
root_index[k] = p
|
root_index[k] = p
|
||||||
print '.',
|
## print '.',
|
||||||
return root_index
|
return root_index
|
||||||
|
|
||||||
|
|
||||||
@ -390,6 +390,8 @@ class IndexWithCache(Index):
|
|||||||
'''
|
'''
|
||||||
objutils.createonaccess('_cache', dict)
|
objutils.createonaccess('_cache', dict)
|
||||||
|
|
||||||
|
__sync__ = False
|
||||||
|
|
||||||
def __getitem__(self, name):
|
def __getitem__(self, name):
|
||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
@ -401,6 +403,8 @@ class IndexWithCache(Index):
|
|||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
self._cache[name] = value
|
self._cache[name] = value
|
||||||
|
if self.__sync__:
|
||||||
|
self.cache_flush(name)
|
||||||
##!!!
|
##!!!
|
||||||
def __delitem__(self, name):
|
def __delitem__(self, name):
|
||||||
'''
|
'''
|
||||||
@ -418,10 +422,16 @@ class IndexWithCache(Index):
|
|||||||
|
|
||||||
# cache management...
|
# cache management...
|
||||||
##!!! test !!!##
|
##!!! test !!!##
|
||||||
def cache_flush(self):
|
def cache_flush(self, *keys):
|
||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
save_file_index(self._cache, self._path)
|
if keys == ():
|
||||||
|
return save_file_index(self._cache, self._path)
|
||||||
|
flush = {}
|
||||||
|
for k in keys:
|
||||||
|
flush[k] = self[k]
|
||||||
|
return save_file_index(flush, self._path)
|
||||||
|
|
||||||
def cache_drop(self):
|
def cache_drop(self):
|
||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
@ -481,6 +491,12 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
pack_file_index(ic._path, keep_files=False)
|
pack_file_index(ic._path, keep_files=False)
|
||||||
|
|
||||||
|
ic.__sync__ = True
|
||||||
|
|
||||||
|
ic['111111111111111111111111111111111'] = {}
|
||||||
|
|
||||||
|
pack_file_index(ic._path, keep_files=False)
|
||||||
|
|
||||||
os.remove(os.path.join('test', 'index', 'index.pack'))
|
os.remove(os.path.join('test', 'index', 'index.pack'))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user