mirror of
https://github.com/NewFuture/DDNS.git
synced 2022-04-19 20:24:44 +00:00
update cache #197
This commit is contained in:
@@ -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
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user