from mailbox_state import MailboxState
CACHE_FILENAME = "message_cache.dat"
-CACHE_VERSION = 1
+CACHE_VERSION = "1"
class CachingData:
"""This class is responsible for the caching of data."""
# class attributes
# integer for version of the cache
version = None
+ # boolean flag which indicates fallback mode of the cache
+ fallback_to_date_header = None
# dictionary of usernames as keys and dictionaries as values
# the second dictionaries have unique mailbox keys and mailboxes as values
data = None
- def __init__(self):
+ def __init__(self, fallback_mode):
# open data file or create one and initialize date if not found
try:
cachefile = open(CACHE_FILENAME, 'rb')
- self.version, self.data = pickle.load(cachefile)
+ cache_info, self.data = pickle.load(cachefile)
+ cache_info = cache_info.split(' ')
+ self.version = cache_info[0]
if(self.version != CACHE_VERSION):
logging.warning("Cache file has version %s and the script version is %s. Deleting cache.",
self.version, CACHE_VERSION)
raise IOError
+ self.fallback_to_date_header = cache_info[1]
+ if(self.fallback_to_date_header != str(fallback_mode)):
+ logging.warning("Cache file date fallback mode setting is different than current settings. Deleting cache.")
+ raise IOError
logging.info("Cache file %s loaded", CACHE_FILENAME)
logging.debug("%s users found.", len(self.data))
except IOError:
self.version = CACHE_VERSION
+ stored_cache_info = self.version + ' ' + str(fallback_mode)
self.data = {}
with open(CACHE_FILENAME, 'wb') as cachefile:
- pickle.dump((self.version, self.data), cachefile)
+ pickle.dump((stored_cache_info, self.data), cachefile)
def __del__(self):
# create temporary file first
return
# serialize in file
- pickle.dump((self.version, self.data), cachefile)
+ stored_cache_info = self.version + ' ' + self.fallback_to_date_header
+ pickle.dump((stored_cache_info, self.data), cachefile)
logging.debug("%s users stored.", len(self.data))
# handle windows non-atomic rename