Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nouiWithSpringMVC
Overview
Overview
Details
Activity
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
gechengyang
nouiWithSpringMVC
Commits
59bd9a1b
Commit
59bd9a1b
authored
Jan 21, 2021
by
WeiCong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化缓存模块
parent
4f89efa8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
23 deletions
+38
-23
AbstractCache.java
...n/java/org/sss/presentation/noui/cache/AbstractCache.java
+35
-18
RedisCache.java
...main/java/org/sss/presentation/noui/cache/RedisCache.java
+3
-5
eibs-container-3.5.0.jar
src/main/webapp/WEB-INF/lib/eibs-container-3.5.0.jar
+0
-0
eibs-hibernatesupport-2.0.0.jar
src/main/webapp/WEB-INF/lib/eibs-hibernatesupport-2.0.0.jar
+0
-0
eibs-pojosupport-2.0.0.jar
src/main/webapp/WEB-INF/lib/eibs-pojosupport-2.0.0.jar
+0
-0
No files found.
src/main/java/org/sss/presentation/noui/cache/AbstractCache.java
View file @
59bd9a1b
...
...
@@ -4,6 +4,8 @@ import org.hibernate.Criteria;
import
org.hibernate.Query
;
import
org.hibernate.internal.QueryImpl
;
import
org.sss.common.model.CacheController
;
import
org.sss.common.model.CacheKey
;
import
org.sss.common.model.CacheList
;
import
org.sss.common.model.IModuleList
;
import
org.sss.module.pojo.EibsResultSet
;
import
org.sss.presentation.noui.api.exception.NoUiException
;
...
...
@@ -17,17 +19,27 @@ public abstract class AbstractCache implements CacheController {
public
static
final
ThreadLocal
paginationMap
=
new
ThreadLocal
();
protected
final
String
cacheName
;
final
String
SPLIT
=
"__"
;
final
String
NULL
=
"NULL"
;
final
String
NULL
=
"NULL"
;
public
AbstractCache
(
String
redis_cache
)
{
this
.
cacheName
=
redis_cache
;
}
@Override
public
List
cacheRead
(
Object
o
,
long
keepAlive
,
int
maxSize
,
int
offset
)
{
List
lst
=
null
;
String
key
=
generateKey
(
o
,
maxSize
,
offset
);
lst
=
doCacheRead
(
key
);
public
CacheList
cacheRead
(
CacheKey
cacheKey
,
long
keepAlive
,
int
maxSize
,
int
offset
)
{
Object
o
=
cacheKey
.
getKey
();
String
fullSizeKey
=
generateKey
(
o
);
int
fullSize
=
(
int
)
doCacheRead
(
fullSizeKey
);
if
(
fullSize
==
0
)
{
try
{
fullSize
=
cacheKey
.
getFullSize
();
doCacheWrite
(
fullSizeKey
,
fullSize
,
keepAlive
);
}
catch
(
Exception
e
)
{
throw
new
NoUiException
(
"["
+
this
.
cacheName
+
"]执行getFullSize时出现异常"
,
e
);
}
}
String
valKey
=
generateValKey
(
o
,
maxSize
,
offset
);
List
lst
=
(
List
)
doCacheRead
(
valKey
);
if
(
lst
==
null
)
{
if
(
o
instanceof
Criteria
)
{
Criteria
criteria
=
(
Criteria
)
o
;
...
...
@@ -61,12 +73,25 @@ public abstract class AbstractCache implements CacheController {
throw
new
NoUiException
(
"["
+
this
.
cacheName
+
"]执行sql出现异常"
,
e
);
}
}
doCacheWrite
(
k
ey
,
lst
,
keepAlive
);
doCacheWrite
(
valK
ey
,
lst
,
keepAlive
);
}
return
lst
;
return
new
CacheList
(
lst
,
fullSize
)
;
}
private
String
generateKey
(
Object
o
,
int
maxSize
,
int
offset
)
{
private
String
generateValKey
(
Object
o
,
int
maxSize
,
int
offset
)
{
StringBuffer
sb
=
new
StringBuffer
(
generateKey
(
o
));
if
(
maxSize
>
0
)
{
sb
.
append
(
SPLIT
.
intern
());
sb
.
append
(
maxSize
);
}
if
(
offset
>
0
)
{
sb
.
append
(
SPLIT
.
intern
());
sb
.
append
(
offset
);
}
return
sb
.
toString
();
}
private
String
generateKey
(
Object
o
)
{
StringBuffer
sb
=
new
StringBuffer
(
cacheName
);
sb
.
append
(
SPLIT
.
intern
());
sb
.
append
(
o
.
getClass
().
getSimpleName
()).
append
(
SPLIT
.
intern
());
...
...
@@ -87,14 +112,6 @@ public abstract class AbstractCache implements CacheController {
}
}
}
if
(
maxSize
>
0
)
{
sb
.
append
(
SPLIT
.
intern
());
sb
.
append
(
maxSize
);
}
if
(
offset
>
0
)
{
sb
.
append
(
SPLIT
.
intern
());
sb
.
append
(
offset
);
}
return
sb
.
toString
();
}
...
...
@@ -112,7 +129,7 @@ public abstract class AbstractCache implements CacheController {
moduleList
.
setPage
(
paginationItem
.
get
(
Constants
.
PAGINATION_INDEX
));
}
protected
abstract
Lis
t
doCacheRead
(
String
key
);
protected
abstract
Objec
t
doCacheRead
(
String
key
);
protected
abstract
void
doCacheWrite
(
String
key
,
Lis
t
lst
,
long
keepAlive
);
protected
abstract
void
doCacheWrite
(
String
key
,
Objec
t
lst
,
long
keepAlive
);
}
src/main/java/org/sss/presentation/noui/cache/RedisCache.java
View file @
59bd9a1b
...
...
@@ -3,24 +3,22 @@ package org.sss.presentation.noui.cache;
import
org.sss.presentation.noui.api.exception.NoUiException
;
import
org.sss.presentation.noui.util.RedisUtil
;
import
java.util.List
;
public
class
RedisCache
extends
AbstractCache
{
public
RedisCache
()
{
super
(
"REDIS_CACHE"
);
}
@Override
protected
Lis
t
doCacheRead
(
String
key
)
{
protected
Objec
t
doCacheRead
(
String
key
)
{
try
{
return
(
List
)
RedisUtil
.
get
(
key
);
return
RedisUtil
.
get
(
key
);
}
catch
(
Exception
e
)
{
throw
new
NoUiException
(
"从缓存["
+
this
.
cacheName
+
"]中获取key="
+
key
+
"的值出现异常"
,
e
);
}
}
@Override
protected
void
doCacheWrite
(
String
key
,
Lis
t
lst
,
long
keepAlive
)
{
protected
void
doCacheWrite
(
String
key
,
Objec
t
lst
,
long
keepAlive
)
{
try
{
RedisUtil
.
set
(
key
,
lst
,
(
int
)
(
keepAlive
/
1000
));
}
catch
(
Exception
e
)
{
...
...
src/main/webapp/WEB-INF/lib/eibs-container-3.5.0.jar
View file @
59bd9a1b
No preview for this file type
src/main/webapp/WEB-INF/lib/eibs-hibernatesupport-2.0.0.jar
View file @
59bd9a1b
No preview for this file type
src/main/webapp/WEB-INF/lib/eibs-pojosupport-2.0.0.jar
View file @
59bd9a1b
No preview for this file type
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