shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.iplatform.chat.cache;
 
import com.iplatform.chat.ChatSession;
import com.iplatform.chat.ChatSessionCache;
import com.iplatform.chat.Constants;
import com.iplatform.chat.service.ChatDialogServiceImpl;
import com.iplatform.chat.util.ChatUtils;
import com.iplatform.model.po.ChatDialog;
import com.walker.support.redis.cache.RedisCacheProvider;
 
public class RedisChatSessionCache extends RedisCacheProvider<ChatSession> implements ChatSessionCache {
 
    public RedisChatSessionCache(){
        this.setUseRedis(true);
        this.setLoadPage(false);
    }
 
    @Override
    public ChatSession get(long id) {
        ChatSession session = this.getCacheData(String.valueOf(id));
        if(session == null){
            ChatDialog dialog = this.chatDialogService.get(new ChatDialog(id));
            if(dialog == null){
                return null;
            }
            session = ChatUtils.acquireChatSession(dialog);
            this.putCacheData(String.valueOf(id), session);
        }
        return session;
    }
 
    @Override
    public void save(ChatSession category) {
        this.putCacheData(String.valueOf(category.getId()), category);
    }
 
    @Override
    public void update(ChatSession category) {
        this.updateCacheData(String.valueOf(category.getId()), category);
    }
 
    @Override
    public void remove(long id) {
        this.removeCacheData(String.valueOf(id));
    }
 
    @Override
    public String getProviderName() {
        return Constants.CACHE_NAME_CHAT_SESSION;
    }
 
    @Override
    public Class<?> getProviderType() {
        return ChatSession.class;
    }
 
    public void setChatDialogService(ChatDialogServiceImpl chatDialogService) {
        this.chatDialogService = chatDialogService;
    }
 
    private ChatDialogServiceImpl chatDialogService;
}