Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
eb42757f
Commit
eb42757f
authored
Oct 12, 2022
by
Future
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
本地缓存
parent
afb3ef6f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
38 deletions
+51
-38
core/src/main/java/com/wecloud/im/service/EhcacheService.java
+1
-1
core/src/main/java/com/wecloud/im/service/ImClientService.java
+1
-1
core/src/main/java/com/wecloud/im/service/impl/ImClientServiceImpl.java
+49
-36
No files found.
core/src/main/java/com/wecloud/im/service/EhcacheService.java
View file @
eb42757f
...
@@ -59,7 +59,7 @@ public class EhcacheService {
...
@@ -59,7 +59,7 @@ public class EhcacheService {
}
}
}
}
@Cacheable
(
value
=
"business"
,
key
=
"#id"
)
//
@Cacheable(value = "business", key = "#id")
public
ImClient
getEhCacheClient
(
Long
id
)
{
public
ImClient
getEhCacheClient
(
Long
id
)
{
return
imClientService
.
getCacheImClient
(
id
);
return
imClientService
.
getCacheImClient
(
id
);
}
}
...
...
core/src/main/java/com/wecloud/im/service/ImClientService.java
View file @
eb42757f
...
@@ -144,7 +144,7 @@ public interface ImClientService extends BaseService<ImClient> {
...
@@ -144,7 +144,7 @@ public interface ImClientService extends BaseService<ImClient> {
ImClient
getCacheImClient
(
Long
applicationId
,
String
clientId
);
ImClient
getCacheImClient
(
Long
applicationId
,
String
clientId
);
void
deleteCacheImClient
(
Long
applicationId
,
String
clientId
);
void
deleteCacheImClient
(
ImClient
client
);
/**
/**
* 根据ID获取client对象,有缓存
* 根据ID获取client对象,有缓存
...
...
core/src/main/java/com/wecloud/im/service/impl/ImClientServiceImpl.java
View file @
eb42757f
package
com
.
wecloud
.
im
.
service
.
impl
;
package
com
.
wecloud
.
im
.
service
.
impl
;
import
io.geekidea.springbootplus.framework.common.exception.BusinessException
;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
io.geekidea.springbootplus.framework.core.pagination.PageInfo
;
import
io.geekidea.springbootplus.framework.core.pagination.Paging
;
import
io.geekidea.springbootplus.framework.shiro.jwt.JwtToken
;
import
io.geekidea.springbootplus.framework.shiro.util.JwtUtil
;
import
io.geekidea.springbootplus.framework.shiro.util.SecurityUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
com.alibaba.fastjson.TypeReference
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
...
@@ -30,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
...
@@ -30,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.chanjx.utils.StringUtils
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
import
com.wecloud.dispatch.extend.ActionRequest
;
import
com.wecloud.dispatch.extend.ActionRequest
;
...
@@ -65,7 +44,26 @@ import com.wecloud.im.vo.ClientInfoVo;
...
@@ -65,7 +44,26 @@ import com.wecloud.im.vo.ClientInfoVo;
import
com.wecloud.im.vo.GetInfoListVo
;
import
com.wecloud.im.vo.GetInfoListVo
;
import
com.wecloud.im.vo.MyInfoVo
;
import
com.wecloud.im.vo.MyInfoVo
;
import
com.wecloud.im.ws.utils.RedisUtils
;
import
com.wecloud.im.ws.utils.RedisUtils
;
import
com.wecloud.utils.JsonUtils
;
import
com.wecloud.utils.SnowflakeUtil
;
import
com.wecloud.utils.SnowflakeUtil
;
import
io.geekidea.springbootplus.framework.common.exception.BusinessException
;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
io.geekidea.springbootplus.framework.core.pagination.PageInfo
;
import
io.geekidea.springbootplus.framework.core.pagination.Paging
;
import
io.geekidea.springbootplus.framework.shiro.jwt.JwtToken
;
import
io.geekidea.springbootplus.framework.shiro.util.JwtUtil
;
import
io.geekidea.springbootplus.framework.shiro.util.SecurityUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.time.Duration
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* 终端表 服务实现类
* 终端表 服务实现类
...
@@ -75,7 +73,6 @@ import com.wecloud.utils.SnowflakeUtil;
...
@@ -75,7 +73,6 @@ import com.wecloud.utils.SnowflakeUtil;
*/
*/
@Slf4j
@Slf4j
@Service
@Service
@CacheConfig
(
cacheNames
=
"client"
)
public
class
ImClientServiceImpl
extends
BaseServiceImpl
<
ImClientMapper
,
ImClient
>
implements
ImClientService
{
public
class
ImClientServiceImpl
extends
BaseServiceImpl
<
ImClientMapper
,
ImClient
>
implements
ImClientService
{
@Autowired
@Autowired
...
@@ -115,7 +112,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
...
@@ -115,7 +112,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
imClientMapper
.
updateById
(
curentClient
);
imClientMapper
.
updateById
(
curentClient
);
// 清除client的redis缓存
// 清除client的redis缓存
deleteCacheImClient
(
curentClient
.
getFkAppid
(),
curentClient
.
getClientId
()
);
deleteCacheImClient
(
curentClient
);
return
true
;
return
true
;
}
}
...
@@ -127,7 +124,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
...
@@ -127,7 +124,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
imClientMapper
.
updateById
(
curentClient
);
imClientMapper
.
updateById
(
curentClient
);
// 清除client的redis缓存
// 清除client的redis缓存
deleteCacheImClient
(
curentClient
.
getFkAppid
(),
curentClient
.
getClientId
()
);
deleteCacheImClient
(
curentClient
);
return
true
;
return
true
;
}
}
...
@@ -141,7 +138,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
...
@@ -141,7 +138,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
imClientMapper
.
updateById
(
curentClient
);
imClientMapper
.
updateById
(
curentClient
);
// 清除client的redis缓存
// 清除client的redis缓存
deleteCacheImClient
(
curentClient
.
getFkAppid
(),
curentClient
.
getClientId
()
);
deleteCacheImClient
(
curentClient
);
return
true
;
return
true
;
}
}
...
@@ -215,7 +212,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
...
@@ -215,7 +212,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
imClientMapper
.
updateById
(
curentClient
);
imClientMapper
.
updateById
(
curentClient
);
// 清除client的redis缓存
// 清除client的redis缓存
deleteCacheImClient
(
curentClient
.
getFkAppid
(),
curentClient
.
getClientId
()
);
deleteCacheImClient
(
curentClient
);
return
true
;
return
true
;
}
}
...
@@ -308,26 +305,42 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
...
@@ -308,26 +305,42 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
}
}
@Override
@Override
// @Cacheable(key = "#p0+#p1")
public
ImClient
getCacheImClient
(
Long
applicationId
,
String
clientId
)
{
public
ImClient
getCacheImClient
(
Long
applicationId
,
String
clientId
)
{
return
this
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
String
key
=
"app_client_"
+
applicationId
+
clientId
;
String
clientStr
=
redisUtils
.
getKey
(
key
);
if
(
StringUtils
.
isNotBlank
(
clientStr
))
{
return
JsonUtils
.
decodeJson
(
clientStr
,
ImClient
.
class
);
}
ImClient
client
=
this
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
.
eq
(
ImClient:
:
getFkAppid
,
applicationId
)
.
eq
(
ImClient:
:
getFkAppid
,
applicationId
)
.
eq
(
ImClient:
:
getClientId
,
clientId
));
.
eq
(
ImClient:
:
getClientId
,
clientId
));
if
(
client
==
null
)
{
return
null
;
}
redisUtils
.
addKey
(
key
,
JsonUtils
.
encodeJson
(
client
),
Duration
.
ofHours
(
1
));
return
client
;
}
}
@Override
@Override
@CacheEvict
(
key
=
"#p0+#p1"
)
public
void
deleteCacheImClient
(
ImClient
client
)
{
public
void
deleteCacheImClient
(
Long
applicationId
,
String
clientId
)
{
String
key
=
"app_client_"
+
client
.
getFkAppid
()
+
client
.
getClientId
();
redisUtils
.
delKey
(
key
);
redisUtils
.
delKey
(
"client_"
+
client
.
getId
());
}
}
@Override
@Override
@Cacheable
(
key
=
"#p0"
)
public
ImClient
getCacheImClient
(
Long
id
)
{
public
ImClient
getCacheImClient
(
Long
id
)
{
return
imClientMapper
.
selectById
(
id
);
String
key
=
"client_"
+
id
;
String
clientStr
=
redisUtils
.
getKey
(
key
);
if
(
StringUtils
.
isNotBlank
(
clientStr
))
{
return
JsonUtils
.
decodeJson
(
clientStr
,
ImClient
.
class
);
}
}
ImClient
client
=
imClientMapper
.
selectById
(
id
);
@CacheEvict
(
key
=
"#p0"
)
if
(
client
==
null
)
{
public
void
deleteCacheImClient
(
Long
id
)
{
return
null
;
}
redisUtils
.
addKey
(
key
,
JsonUtils
.
encodeJson
(
client
),
Duration
.
ofHours
(
1
));
return
client
;
}
}
@Override
@Override
...
...
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