update cache #197

This commit is contained in:
NewFututre
2020-09-07 22:08:22 +08:00
parent 4e0de3d02b
commit f126bf8f84
2 changed files with 13 additions and 11 deletions
+4 -2
View File
@@ -11,7 +11,7 @@ from json import load as loadjson, dump as dumpjson
from time import ctime
from os import path, environ, stat, name as os_name
from tempfile import gettempdir
from logging import DEBUG, basicConfig, info, warning, error
from logging import DEBUG, basicConfig, info, warning, error, debug
from subprocess import check_output
import sys
@@ -185,9 +185,11 @@ def main():
cache = get_config('cache', True) and Cache(CACHE_FILE)
if cache is False:
info("Cache is disabled!")
elif len(cache) < 1 or get_config.time >= cache.time:
elif get_config.time >= cache.time:
warning("Cache file is out of dated.")
cache.clear()
elif not cache:
debug("Cache is empty.")
update_ip('4', cache, dns, proxy_list)
update_ip('6', cache, dns, proxy_list)
+9 -9
View File
@@ -9,7 +9,7 @@ from os import path, stat
from pickle import dump, load
from time import time
from logging import info, debug, error
from logging import info, debug, warning
try:
from collections.abc import MutableMapping
@@ -51,17 +51,17 @@ class Cache(MutableMapping):
try:
self.__data = load(data)
self.__time = stat(file).st_mtime
return self
except ValueError:
self.__data = {}
self.__time = time()
pass
except Exception as e:
error(e)
self.__data = {}
self.__time = time()
warning(e)
else:
info('cache file not exist')
self.__data = {}
self.__time = time()
self.__data = {}
self.__time = time()
self.__changed = True
return self
def data(self, key=None, default=None):
@@ -106,7 +106,7 @@ class Cache(MutableMapping):
self.__time = time()
def clear(self):
if self.data():
if self.data() is not None:
self.__data = {}
self.__update()