liulin
2025-07-01 c311cb1a9ecad57ac15cca5ea4581f0aa2574762
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
package com.lunhan.water.service;
 
import com.lunhan.water.repository.impl.AdminMenuMapperImpl;
import com.lunhan.water.repository.po.AdminMenuPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.function.Function;
 
@Service
public class AdminMenuService {
    @Autowired
    private AdminMenuMapperImpl dao;
 
    /**
     * 获取所有菜单(缓存)
     */
    //@Cacheable(cacheManager = "json4RedisCacheManager",value = "userCache", key = "#id")
    //@Cacheable(cacheManager = "json4RedisCacheManager",value = "userCache", key = "#user.id")
    @Cacheable(cacheManager = "json4RedisCacheManager", value = "adminMenusCache")
    public List<AdminMenuPO> listAllWithCache() {
        return dao.getList();
    }
 
    // 删除菜单缓存
    @CacheEvict(cacheNames = "adminMenusCache", allEntries = true)
    public void removeListAllCache() {
    }
 
 
    /**
     * 获取用户拥有的菜单(缓存)
     */
    @Cacheable(cacheManager = "json4RedisCacheManager", value = "userMenusCache", key = "#id")
    public List<AdminMenuPO> listUserAllWithCache(Long id, List<Long> listRoleId, Function<List<Long>, List<AdminMenuPO>> funcGetUserMenu) {
        return funcGetUserMenu.apply(listRoleId);
    }
    // 删除指定用户拥有的菜单缓存
    @CacheEvict(cacheNames = "userMenusCache", key = "#id")
    public void removeUserMenuCache(Long id) {
    }
    // 删除所有用户拥有的菜单缓存
    @CacheEvict(cacheNames = "userMenusCache", allEntries = true)
    public void removeAllUserMenuCache() {
    }
}