kcwcache 1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kcwcache-1.0/PKG-INFO +13 -0
- kcwcache-1.0/kcwcache/__init__.py +4 -0
- kcwcache-1.0/kcwcache/cacheclass.py +321 -0
- kcwcache-1.0/kcwcache.egg-info/PKG-INFO +13 -0
- kcwcache-1.0/kcwcache.egg-info/SOURCES.txt +8 -0
- kcwcache-1.0/kcwcache.egg-info/dependency_links.txt +1 -0
- kcwcache-1.0/kcwcache.egg-info/requires.txt +1 -0
- kcwcache-1.0/kcwcache.egg-info/top_level.txt +1 -0
- kcwcache-1.0/setup.cfg +4 -0
- kcwcache-1.0/setup.py +57 -0
kcwcache-1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 1.2
|
|
2
|
+
Name: kcwcache
|
|
3
|
+
Version: 1.0
|
|
4
|
+
Summary: kcwcache
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
Author: 百里
|
|
7
|
+
Author-email: kcwebs@kwebapp.cn
|
|
8
|
+
Maintainer: 坤坤
|
|
9
|
+
Maintainer-email: fk1402936534@qq.com
|
|
10
|
+
License: MIT License
|
|
11
|
+
Description: UNKNOWN
|
|
12
|
+
Keywords: kcwcache1.0
|
|
13
|
+
Platform: UNKNOWN
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import os,time,hashlib
|
|
3
|
+
import kcwredis
|
|
4
|
+
import time,hashlib
|
|
5
|
+
try:
|
|
6
|
+
from kcwebs.config import cache as cacheconfig
|
|
7
|
+
except:
|
|
8
|
+
cacheconfig={}
|
|
9
|
+
cacheconfig['type']='File' #驱动方式 支持 File Redis Python
|
|
10
|
+
cacheconfig['path']='app/runtime/cachepath' #缓存保存目录
|
|
11
|
+
cacheconfig['expire']=120 #缓存有效期 0表示永久缓存
|
|
12
|
+
cacheconfig['host']='127.0.0.1' #Redis服务器地址
|
|
13
|
+
cacheconfig['port']=6379 #Redis 端口
|
|
14
|
+
cacheconfig['password']='' #Redis登录密码
|
|
15
|
+
cacheconfig['db']=1 #Redis数据库 注:Redis用1或2或3等表示
|
|
16
|
+
cachevalue={}
|
|
17
|
+
def md5(strs):
|
|
18
|
+
"""md5加密"""
|
|
19
|
+
if not strs:
|
|
20
|
+
return strs
|
|
21
|
+
m = hashlib.md5()
|
|
22
|
+
b = strs.encode(encoding='utf-8')
|
|
23
|
+
m.update(b)
|
|
24
|
+
return m.hexdigest()
|
|
25
|
+
def times():
|
|
26
|
+
"""时间戳 精确到秒"""
|
|
27
|
+
return int(time.time())
|
|
28
|
+
def json_decode(jsonstr):
|
|
29
|
+
"""json字符串转python类型"""
|
|
30
|
+
try:
|
|
31
|
+
return eval(jsonstr)
|
|
32
|
+
except Exception:
|
|
33
|
+
return {}
|
|
34
|
+
def is_index(params,index):
|
|
35
|
+
"""判断列表或字典里的索引是否存在
|
|
36
|
+
|
|
37
|
+
params 列表或字典
|
|
38
|
+
|
|
39
|
+
index 索引值
|
|
40
|
+
|
|
41
|
+
return Boolean类型
|
|
42
|
+
"""
|
|
43
|
+
try:
|
|
44
|
+
params[index]
|
|
45
|
+
except KeyError:
|
|
46
|
+
return False
|
|
47
|
+
except IndexError:
|
|
48
|
+
return False
|
|
49
|
+
else:
|
|
50
|
+
return True
|
|
51
|
+
class cacheclass:
|
|
52
|
+
"开发完善中..."
|
|
53
|
+
__name=None
|
|
54
|
+
__values=None
|
|
55
|
+
__cachepath='' #os.path.split(os.path.realpath(__file__))[0]+'/../../../'
|
|
56
|
+
__config=cacheconfig
|
|
57
|
+
__redisobj=None
|
|
58
|
+
__mysqlobj=None
|
|
59
|
+
# def __setmysqlonj(self):
|
|
60
|
+
# conf=config.database
|
|
61
|
+
# if 'host' in self.__config and self.__config['host']:
|
|
62
|
+
# conf['host']=[self.__config['host']]
|
|
63
|
+
# if 'port' in self.__config and self.__config['port']:
|
|
64
|
+
# conf['port']=[self.__config['port']]
|
|
65
|
+
# if 'user' in self.__config and self.__config['user']:
|
|
66
|
+
# conf['user']=[self.__config['user']]
|
|
67
|
+
# if 'password' in self.__config and self.__config['password']:
|
|
68
|
+
# conf['password']=[self.__config['password']]
|
|
69
|
+
# if 'db' in self.__config and self.__config['db']:
|
|
70
|
+
# conf['db']=[self.__config['db']]
|
|
71
|
+
# db=mysql()
|
|
72
|
+
# self.__mysqlobj=db.connect(conf)
|
|
73
|
+
def __setredisobj(self):
|
|
74
|
+
"设置redis链接实例"
|
|
75
|
+
conf=cacheconfig
|
|
76
|
+
if 'host' in self.__config and self.__config['host']:
|
|
77
|
+
conf['host']=self.__config['host']
|
|
78
|
+
if 'port' in self.__config and self.__config['port']:
|
|
79
|
+
conf['port']=self.__config['port']
|
|
80
|
+
if 'password' in self.__config and self.__config['password']:
|
|
81
|
+
conf['password']=self.__config['password']
|
|
82
|
+
if 'db' in self.__config and self.__config['db']:
|
|
83
|
+
conf['db']=self.__config['db']
|
|
84
|
+
if not self.__redisobj:
|
|
85
|
+
self.__redisobj=kcwredis.redis
|
|
86
|
+
self.__redisobj.connect(conf)
|
|
87
|
+
def set_cache(self,name,values,expire = 'no'):
|
|
88
|
+
"""设置缓存
|
|
89
|
+
|
|
90
|
+
参数 name:缓存名
|
|
91
|
+
|
|
92
|
+
参数 values:缓存值
|
|
93
|
+
|
|
94
|
+
参数 expire:缓存有效期 0表示永久 单位 秒
|
|
95
|
+
|
|
96
|
+
return Boolean类型
|
|
97
|
+
"""
|
|
98
|
+
# print(name)
|
|
99
|
+
# exit()
|
|
100
|
+
self.__name=name
|
|
101
|
+
self.__values=values
|
|
102
|
+
if expire != 'no':
|
|
103
|
+
self.__config['expire']=int(expire)
|
|
104
|
+
return self.__seltype('set')
|
|
105
|
+
def get_cache(self,name):
|
|
106
|
+
"""获取缓存
|
|
107
|
+
|
|
108
|
+
return 或者的值
|
|
109
|
+
"""
|
|
110
|
+
self.__name=name
|
|
111
|
+
return self.__seltype('get')
|
|
112
|
+
def del_cache(self,name):
|
|
113
|
+
"""删除缓存
|
|
114
|
+
|
|
115
|
+
return Boolean类型
|
|
116
|
+
"""
|
|
117
|
+
self.__name=name
|
|
118
|
+
return self.__seltype('del')
|
|
119
|
+
def set_config(self,congig):
|
|
120
|
+
"""设置缓存配置
|
|
121
|
+
"""
|
|
122
|
+
self.__config=congig
|
|
123
|
+
return self
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def __seltype(self,types):
|
|
127
|
+
"""选择缓存"""
|
|
128
|
+
# m = hashlib.md5()
|
|
129
|
+
# b = self.__name.encode(encoding='utf-8')
|
|
130
|
+
# m.update(b)
|
|
131
|
+
self.__name=md5(self.__name)
|
|
132
|
+
if self.__config['type'] == 'File':
|
|
133
|
+
if types == 'set':
|
|
134
|
+
return self.__setfilecache()
|
|
135
|
+
elif types=='get':
|
|
136
|
+
return self.__getfilecache()
|
|
137
|
+
elif types=='del':
|
|
138
|
+
return self.__delfilecache()
|
|
139
|
+
elif self.__config['type'] == 'Redis':
|
|
140
|
+
self.__setredisobj()
|
|
141
|
+
if types == 'set':
|
|
142
|
+
return self.__setrediscache()
|
|
143
|
+
elif types=='get':
|
|
144
|
+
return self.__getrediscache()
|
|
145
|
+
elif types=='del':
|
|
146
|
+
return self.__delrediscache()
|
|
147
|
+
# elif self.__config['type'] == 'MySql':
|
|
148
|
+
# self.__setmysqlonj()
|
|
149
|
+
# if types == 'set':
|
|
150
|
+
# return self.__setmysqlcache()
|
|
151
|
+
# elif types == 'get':
|
|
152
|
+
# return self.__getmysqlcache()
|
|
153
|
+
# elif types == 'del':
|
|
154
|
+
# return self.__delmysqlcache()
|
|
155
|
+
elif self.__config['type'] == 'Python':
|
|
156
|
+
if types == 'set':
|
|
157
|
+
return self.__setpythoncache()
|
|
158
|
+
elif types == 'get':
|
|
159
|
+
return self.__getpythoncache()
|
|
160
|
+
elif types == 'del':
|
|
161
|
+
return self.__delpythoncache()
|
|
162
|
+
else:
|
|
163
|
+
raise Exception("缓存类型错误")
|
|
164
|
+
def __setpythoncache(self):
|
|
165
|
+
"""设置python缓存
|
|
166
|
+
|
|
167
|
+
return Boolean类型
|
|
168
|
+
"""
|
|
169
|
+
data={
|
|
170
|
+
'expire':self.__config['expire'],
|
|
171
|
+
'time':times(),
|
|
172
|
+
'values':self.__values
|
|
173
|
+
}
|
|
174
|
+
cachevalue[self.__name]=data
|
|
175
|
+
return True
|
|
176
|
+
def __getpythoncache(self):
|
|
177
|
+
"""获取python缓存
|
|
178
|
+
|
|
179
|
+
return 缓存的值
|
|
180
|
+
"""
|
|
181
|
+
try:
|
|
182
|
+
ar=cachevalue[self.__name]
|
|
183
|
+
except KeyError:
|
|
184
|
+
return ""
|
|
185
|
+
else:
|
|
186
|
+
if ar['expire'] > 0:
|
|
187
|
+
if (times()-ar['time']) > ar['expire']:
|
|
188
|
+
self.__delpythoncache()
|
|
189
|
+
return ""
|
|
190
|
+
else:
|
|
191
|
+
return ar['values']
|
|
192
|
+
else:
|
|
193
|
+
return ar['values']
|
|
194
|
+
def __delpythoncache(self):
|
|
195
|
+
"""删除python缓存
|
|
196
|
+
|
|
197
|
+
return Boolean类型
|
|
198
|
+
"""
|
|
199
|
+
try:
|
|
200
|
+
del cachevalue[self.__name]
|
|
201
|
+
except KeyError:
|
|
202
|
+
pass
|
|
203
|
+
return True
|
|
204
|
+
# def __setmysqlcache(self): ########################################################################################
|
|
205
|
+
# """设置mysql缓存
|
|
206
|
+
|
|
207
|
+
# return Boolean类型
|
|
208
|
+
# """
|
|
209
|
+
# data=[str(self.__values)]
|
|
210
|
+
# strs="["
|
|
211
|
+
# for k in data:
|
|
212
|
+
# strs=strs+k
|
|
213
|
+
# strs=strs+"]"
|
|
214
|
+
# k=self.__mysqlobj.table('fanshukeji_core_cache').where("name",self.__name).count('id')
|
|
215
|
+
# self.__setmysqlonj()
|
|
216
|
+
# if k:
|
|
217
|
+
# return self.__mysqlobj.table('fanshukeji_core_cache').where("name",self.__name).update({"val":strs,"expire":self.__config['expire'],"time":times()})
|
|
218
|
+
# else:
|
|
219
|
+
# return self.__mysqlobj.table('fanshukeji_core_cache').insert({"name":self.__name,"val":strs,"expire":self.__config['expire'],"time":times()})
|
|
220
|
+
# def __getmysqlcache(self):
|
|
221
|
+
# """获取mysql缓存
|
|
222
|
+
|
|
223
|
+
# return 缓存的值
|
|
224
|
+
# """
|
|
225
|
+
# data=self.__mysqlobj.table('fanshukeji_core_cache').where("name",self.__name).find()
|
|
226
|
+
# if data :
|
|
227
|
+
# if data['expire']>0 and times()-data['time']>data['expire']:
|
|
228
|
+
# self.__setmysqlonj()
|
|
229
|
+
# self.__mysqlobj.table('fanshukeji_core_cache').where("name",self.__name).delete()
|
|
230
|
+
# return False
|
|
231
|
+
# else:
|
|
232
|
+
# return eval(data['val'])[0]
|
|
233
|
+
# else:
|
|
234
|
+
# return False
|
|
235
|
+
# def __delmysqlcache(self):
|
|
236
|
+
# """删除mysql缓存
|
|
237
|
+
|
|
238
|
+
# return Boolean类型
|
|
239
|
+
# """
|
|
240
|
+
# return self.__mysqlobj.table('fanshukeji_core_cache').where("name",self.__name).delete()
|
|
241
|
+
def __setrediscache(self):
|
|
242
|
+
"""设置redis缓存
|
|
243
|
+
|
|
244
|
+
return Boolean类型
|
|
245
|
+
"""
|
|
246
|
+
data=self.__values
|
|
247
|
+
try:
|
|
248
|
+
if self.__config['expire']:
|
|
249
|
+
self.__redisobj.set(self.__name,data,self.__config['expire'])
|
|
250
|
+
else:
|
|
251
|
+
self.__redisobj.set(self.__name,data)
|
|
252
|
+
except:
|
|
253
|
+
return False
|
|
254
|
+
return True
|
|
255
|
+
def __getrediscache(self):
|
|
256
|
+
"""获取redis缓存
|
|
257
|
+
|
|
258
|
+
return 缓存的值
|
|
259
|
+
"""
|
|
260
|
+
lists=self.__redisobj.get(self.__name)
|
|
261
|
+
if lists:
|
|
262
|
+
return lists
|
|
263
|
+
else:
|
|
264
|
+
return False
|
|
265
|
+
def __delrediscache(self):
|
|
266
|
+
"""删除redis缓存
|
|
267
|
+
|
|
268
|
+
return int类型
|
|
269
|
+
"""
|
|
270
|
+
return self.__redisobj.delete(self.__name)
|
|
271
|
+
def __setfilecache(self):
|
|
272
|
+
"""设置文件缓存
|
|
273
|
+
|
|
274
|
+
return Boolean类型
|
|
275
|
+
"""
|
|
276
|
+
data={
|
|
277
|
+
'expire':self.__config['expire'],
|
|
278
|
+
'time':times(),
|
|
279
|
+
'values':self.__values
|
|
280
|
+
}
|
|
281
|
+
if not os.path.exists(self.__config['path']):
|
|
282
|
+
os.makedirs(self.__config['path']) #多层创建目录
|
|
283
|
+
f=open(self.__config['path']+"/"+self.__name,"w")
|
|
284
|
+
f.write(str(data))
|
|
285
|
+
f.close()
|
|
286
|
+
return True
|
|
287
|
+
def __getfilecache(self):
|
|
288
|
+
"""获取文件缓存
|
|
289
|
+
|
|
290
|
+
return 缓存的值
|
|
291
|
+
"""
|
|
292
|
+
try:
|
|
293
|
+
f=open(self.__config['path']+"/"+self.__name,"r")
|
|
294
|
+
except Exception:
|
|
295
|
+
return ""
|
|
296
|
+
json_str=f.read()
|
|
297
|
+
f.close()
|
|
298
|
+
ar=json_decode(json_str)
|
|
299
|
+
|
|
300
|
+
if ar and is_index(ar,'expire') and ar['expire'] > 0:
|
|
301
|
+
if (times()-ar['time']) > ar['expire']:
|
|
302
|
+
self.__delfilecache()
|
|
303
|
+
return ""
|
|
304
|
+
else:
|
|
305
|
+
return ar['values']
|
|
306
|
+
elif ar and is_index(ar,'values'):
|
|
307
|
+
return ar['values']
|
|
308
|
+
else:
|
|
309
|
+
return ''
|
|
310
|
+
def __delfilecache(self):
|
|
311
|
+
"""删除文件缓存
|
|
312
|
+
|
|
313
|
+
return Boolean类型
|
|
314
|
+
"""
|
|
315
|
+
if not os.path.exists(self.__config['path']+"/"+self.__name):
|
|
316
|
+
return True
|
|
317
|
+
try:
|
|
318
|
+
os.remove(self.__config['path']+"/"+self.__name)
|
|
319
|
+
except:
|
|
320
|
+
return False
|
|
321
|
+
return True
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 1.2
|
|
2
|
+
Name: kcwcache
|
|
3
|
+
Version: 1.0
|
|
4
|
+
Summary: kcwcache
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
Author: 百里
|
|
7
|
+
Author-email: kcwebs@kwebapp.cn
|
|
8
|
+
Maintainer: 坤坤
|
|
9
|
+
Maintainer-email: fk1402936534@qq.com
|
|
10
|
+
License: MIT License
|
|
11
|
+
Description: UNKNOWN
|
|
12
|
+
Keywords: kcwcache1.0
|
|
13
|
+
Platform: UNKNOWN
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kcwredis>=1.1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kcwcache
|
kcwcache-1.0/setup.cfg
ADDED
kcwcache-1.0/setup.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
# 打包上传 python setup.py sdist upload
|
|
3
|
+
# 打包并安装 python setup.py sdist install
|
|
4
|
+
# twine upload --repository-url https://test.pypi.org/legacy/ dist/* #上传到测试
|
|
5
|
+
# pip install --index-url https://pypi.org/simple/ kcwebs #安装测试服务上的kcwebs pip3 install kcwebs==4.12.4 -i https://pypi.org/simple/
|
|
6
|
+
# 安装 python setup.py install
|
|
7
|
+
############################################# pip3.8 install kcwebs==6.4.15 -i https://pypi.org/simple
|
|
8
|
+
import os,sys
|
|
9
|
+
from setuptools import setup, find_packages,Extension
|
|
10
|
+
current_dir = os.path.abspath(os.path.dirname(__file__))
|
|
11
|
+
sys.path.insert(0, current_dir)
|
|
12
|
+
confkcws={}
|
|
13
|
+
confkcws['name']='kcwcache'
|
|
14
|
+
confkcws['version']='1.0'
|
|
15
|
+
confkcws['description']='kcwcache'
|
|
16
|
+
confkcws['long_description']=''
|
|
17
|
+
confkcws['license']='MIT License'
|
|
18
|
+
confkcws['url']=''
|
|
19
|
+
confkcws['author']='百里'
|
|
20
|
+
confkcws['author_email']='kcwebs@kwebapp.cn'
|
|
21
|
+
confkcws['maintainer']='坤坤'
|
|
22
|
+
confkcws['maintainer_email']='fk1402936534@qq.com'
|
|
23
|
+
def get_file(folder='./',lists=[]):
|
|
24
|
+
lis=os.listdir(folder)
|
|
25
|
+
for files in lis:
|
|
26
|
+
if not os.path.isfile(folder+"/"+files):
|
|
27
|
+
if files=='__pycache__' or files=='.git':
|
|
28
|
+
pass
|
|
29
|
+
else:
|
|
30
|
+
lists.append(folder+"/"+files)
|
|
31
|
+
get_file(folder+"/"+files,lists)
|
|
32
|
+
else:
|
|
33
|
+
pass
|
|
34
|
+
return lists
|
|
35
|
+
def start():
|
|
36
|
+
b=get_file("kcwcache",['kcwcache'])
|
|
37
|
+
setup(
|
|
38
|
+
name = confkcws["name"],
|
|
39
|
+
version = confkcws["version"],
|
|
40
|
+
keywords = "kcwcache"+confkcws['version'],
|
|
41
|
+
description = confkcws["description"],
|
|
42
|
+
long_description = confkcws["long_description"],
|
|
43
|
+
license = confkcws["license"],
|
|
44
|
+
author = confkcws["author"],
|
|
45
|
+
author_email = confkcws["author_email"],
|
|
46
|
+
maintainer = confkcws["maintainer"],
|
|
47
|
+
maintainer_email = confkcws["maintainer_email"],
|
|
48
|
+
url=confkcws['url'],
|
|
49
|
+
packages = b,
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
install_requires = ['kcwredis>=1.1'], #第三方包
|
|
53
|
+
package_data = {
|
|
54
|
+
'': ['*.html', '*.js','*.css','*.jpg','*.png','*.gif'],
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
start()
|