Skip to content

Commit 2cefc75

Browse files
authored
Merge pull request #203 from NewFuture/update-cache
update cache to resolve #197
2 parents 4e0de3d + f126bf8 commit 2cefc75

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

run.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from time import ctime
1212
from os import path, environ, stat, name as os_name
1313
from tempfile import gettempdir
14-
from logging import DEBUG, basicConfig, info, warning, error
14+
from logging import DEBUG, basicConfig, info, warning, error, debug
1515
from subprocess import check_output
1616

1717
import sys
@@ -185,9 +185,11 @@ def main():
185185
cache = get_config('cache', True) and Cache(CACHE_FILE)
186186
if cache is False:
187187
info("Cache is disabled!")
188-
elif len(cache) < 1 or get_config.time >= cache.time:
188+
elif get_config.time >= cache.time:
189189
warning("Cache file is out of dated.")
190190
cache.clear()
191+
elif not cache:
192+
debug("Cache is empty.")
191193
update_ip('4', cache, dns, proxy_list)
192194
update_ip('6', cache, dns, proxy_list)
193195

util/cache.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pickle import dump, load
1010
from time import time
1111

12-
from logging import info, debug, error
12+
from logging import info, debug, warning
1313

1414
try:
1515
from collections.abc import MutableMapping
@@ -51,17 +51,17 @@ def load(self, file=None):
5151
try:
5252
self.__data = load(data)
5353
self.__time = stat(file).st_mtime
54+
return self
5455
except ValueError:
55-
self.__data = {}
56-
self.__time = time()
56+
pass
5757
except Exception as e:
58-
error(e)
59-
self.__data = {}
60-
self.__time = time()
58+
warning(e)
6159
else:
6260
info('cache file not exist')
63-
self.__data = {}
64-
self.__time = time()
61+
62+
self.__data = {}
63+
self.__time = time()
64+
self.__changed = True
6565
return self
6666

6767
def data(self, key=None, default=None):
@@ -106,7 +106,7 @@ def __update(self):
106106
self.__time = time()
107107

108108
def clear(self):
109-
if self.data():
109+
if self.data() is not None:
110110
self.__data = {}
111111
self.__update()
112112

0 commit comments

Comments
 (0)