Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
52363bf0
Commit
52363bf0
authored
3 years ago
by
张辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix redis cache bug
parent
4769e67a
1 merge request
!2
Dev
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1 addition
and
125 deletions
+1
-125
CacheEvict.java
...e/src/main/java/com/tanpu/community/cache/CacheEvict.java
+0
-12
CacheGet.java
...ice/src/main/java/com/tanpu/community/cache/CacheGet.java
+0
-13
RedisCache.java
...e/src/main/java/com/tanpu/community/cache/RedisCache.java
+1
-1
RedisCacheEvictAspect.java
...java/com/tanpu/community/cache/RedisCacheEvictAspect.java
+0
-41
RedisCacheGetAspect.java
...n/java/com/tanpu/community/cache/RedisCacheGetAspect.java
+0
-58
No files found.
community-service/src/main/java/com/tanpu/community/cache/CacheEvict.java
deleted
100644 → 0
View file @
4769e67a
package
com
.
tanpu
.
community
.
cache
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
@Target
(
ElementType
.
METHOD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
CacheEvict
{
String
prefix
()
default
""
;
}
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/cache/CacheGet.java
deleted
100644 → 0
View file @
4769e67a
package
com
.
tanpu
.
community
.
cache
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
@Target
(
ElementType
.
METHOD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
CacheGet
{
String
prefix
()
default
""
;
int
expireSeconds
()
default
60
;
}
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/cache/RedisCache.java
View file @
52363bf0
...
@@ -56,7 +56,7 @@ public class RedisCache {
...
@@ -56,7 +56,7 @@ public class RedisCache {
private
void
put
(
String
key
,
Object
obj
,
Integer
expireSeconds
)
{
private
void
put
(
String
key
,
Object
obj
,
Integer
expireSeconds
)
{
key
=
cacheName
+
":"
+
key
;
key
=
cacheName
+
":"
+
key
;
String
value
=
J
SON
.
toJSONString
(
obj
);
String
value
=
J
sonUtil
.
toJson
(
obj
);
if
(
expireSeconds
==
0
)
{
if
(
expireSeconds
==
0
)
{
redisHelper
.
set
(
key
,
value
);
redisHelper
.
set
(
key
,
value
);
}
else
{
}
else
{
...
...
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/cache/RedisCacheEvictAspect.java
deleted
100644 → 0
View file @
4769e67a
package
com
.
tanpu
.
community
.
cache
;
import
com.alibaba.fastjson.JSON
;
import
com.tanpu.common.redis.RedisHelper
;
import
com.tanpu.common.redis.RedisKeyHelper
;
import
com.tanpu.community.util.SpringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.stereotype.Component
;
import
java.time.Duration
;
@Aspect
@Component
public
class
RedisCacheEvictAspect
{
private
static
RedisKeyHelper
keyHelper
=
new
RedisKeyHelper
(
"community2_cache:"
);
@Around
(
value
=
"@annotation(com.tanpu.community.cache.CacheEvict)"
)
public
Object
methodAround
(
ProceedingJoinPoint
jp
)
throws
Throwable
{
MethodSignature
ms
=
(
MethodSignature
)
jp
.
getSignature
();
CacheEvict
anno
=
ms
.
getMethod
().
getAnnotation
(
CacheEvict
.
class
);
String
prefix
=
anno
.
prefix
();
RedisHelper
redisHelper
=
SpringUtils
.
getBean
(
RedisHelper
.
class
);
String
key
=
keyHelper
.
buildKeyCustom
(
":"
,
prefix
,
StringUtils
.
joinWith
(
":"
,
jp
.
getArgs
()));
redisHelper
.
delete
(
key
);
try
{
Object
ret
=
jp
.
proceed
();
return
ret
;
}
catch
(
Throwable
t
)
{
// todo wrap this throwable
throw
new
RuntimeException
(
t
);
}
}
}
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/cache/RedisCacheGetAspect.java
deleted
100644 → 0
View file @
4769e67a
package
com
.
tanpu
.
community
.
cache
;
import
com.alibaba.fastjson.JSON
;
import
com.tanpu.common.redis.RedisHelper
;
import
com.tanpu.common.redis.RedisKeyHelper
;
import
com.tanpu.community.util.SpringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.stereotype.Component
;
import
java.time.Duration
;
@Aspect
@Component
public
class
RedisCacheGetAspect
{
private
static
RedisKeyHelper
keyHelper
=
new
RedisKeyHelper
(
"community2_cache:"
);
@Around
(
value
=
"@annotation(com.tanpu.community.cache.CacheGet)"
)
public
Object
methodAround
(
ProceedingJoinPoint
jp
)
throws
Throwable
{
MethodSignature
ms
=
(
MethodSignature
)
jp
.
getSignature
();
CacheGet
anno
=
ms
.
getMethod
().
getAnnotation
(
CacheGet
.
class
);
String
prefix
=
anno
.
prefix
();
int
expireSeconds
=
anno
.
expireSeconds
();
if
(
expireSeconds
<
0
)
{
throw
new
RuntimeException
(
"expire second cannot be negative."
);
}
RedisHelper
redisHelper
=
SpringUtils
.
getBean
(
RedisHelper
.
class
);
String
key
=
keyHelper
.
buildKeyCustom
(
":"
,
prefix
,
StringUtils
.
joinWith
(
":"
,
jp
.
getArgs
()));
String
value
=
redisHelper
.
get
(
key
);
// todo 考虑缓存穿透的问题.
if
(
StringUtils
.
isNotBlank
(
value
))
{
return
JSON
.
parseObject
(
value
,
ms
.
getReturnType
());
}
try
{
Object
ret
=
jp
.
proceed
();
String
putValue
=
ret
==
null
?
"null"
:
JSON
.
toJSONString
(
ret
);
if
(
expireSeconds
==
0
)
{
redisHelper
.
set
(
key
,
putValue
);
}
else
{
redisHelper
.
set
(
key
,
putValue
,
Duration
.
ofSeconds
(
expireSeconds
));
}
return
ret
;
}
catch
(
Throwable
t
)
{
// todo wrap this throwable
throw
new
RuntimeException
(
t
);
}
}
}
This diff is collapsed.
Click to expand it.
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