Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
3d08ffaa
Commit
3d08ffaa
authored
Aug 26, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
默认日期格式的支持
parent
d3d9e878
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
0 deletions
+101
-0
MemoryCacheNullUtil.java
.../java/com/yanzuoguang/util/cache/MemoryCacheNullUtil.java
+101
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/cache/MemoryCacheNullUtil.java
0 → 100644
View file @
3d08ffaa
package
com
.
yanzuoguang
.
util
.
cache
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
/**
* 服务工具类
*
* @author 颜佐光
*/
public
abstract
class
MemoryCacheNullUtil
<
T
,
M
>
{
/**
* 缓存的公司和数据中心Id
* 缓存一个小时
*/
private
MemoryCache
<
M
>
cache
=
new
MemoryCache
<>(
60
*
60
);
/**
* 缓存的公司和数据中心Id
* 缓存一分钟
*/
private
MemoryCache
<
Boolean
>
cacheIsNull
=
new
MemoryCache
<>(
60
);
public
MemoryCacheNullUtil
()
{
}
/**
* 缓存参数
*
* @param cacheSecond
* @param nullSecond
*/
public
MemoryCacheNullUtil
(
int
cacheSecond
,
int
nullSecond
)
{
cache
.
setClearSecond
(
cacheSecond
);
cacheIsNull
.
setClearSecond
(
nullSecond
);
}
/**
* 获取数据中心Id
*
* @param key
* @return
*/
public
M
getCheck
(
T
key
)
{
M
databaseId
=
get
(
key
);
if
(
databaseId
==
null
)
{
throw
new
CodeException
(
"没有找到"
+
key
+
"的数据"
);
}
return
databaseId
;
}
/**
* 获取数据中心Id
*
* @param key
* @return
*/
public
M
get
(
T
key
)
{
String
keyString
=
getKey
(
key
);
M
value
=
cache
.
get
(
keyString
);
if
(
value
==
null
)
{
if
(
StringHelper
.
toBoolean
(
cacheIsNull
.
get
(
keyString
)))
{
return
null
;
}
value
=
getValue
(
key
);
setCache
(
keyString
,
value
);
}
return
value
;
}
/**
* 获取关键字
*
* @param key
* @return
*/
protected
abstract
String
getKey
(
T
key
);
/**
* 获取数据
*
* @param key
* @return
*/
protected
abstract
M
getValue
(
T
key
);
/**
* 写入缓存
*
* @param key
* @param value
*/
protected
void
setCache
(
String
key
,
M
value
)
{
cacheIsNull
.
remove
(
key
);
cache
.
remove
(
key
);
if
(
value
==
null
)
{
cacheIsNull
.
put
(
key
,
true
);
}
else
{
cache
.
put
(
key
,
value
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment