Java Code Examples for net.oschina.j2cache.CacheObject#getValue()
The following examples show how to use
net.oschina.j2cache.CacheObject#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoleServiceImpl.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
@Override public List<Role> findRoleByUserId(Long userId) { String key = key(userId); List<Role> roleList = new ArrayList<>(); CacheObject cacheObject = cacheChannel.get(CacheKey.USER_ROLE, key, (k) -> { roleList.addAll(baseMapper.findRoleByUserId(userId)); return roleList.stream().mapToLong(Role::getId).boxed().collect(Collectors.toList()); }); if (cacheObject.getValue() == null) { return Collections.emptyList(); } if (!roleList.isEmpty()) { // TODO 异步性能 更加 roleList.forEach((item) -> { String itemKey = key(item.getId()); cacheChannel.set(ROLE, itemKey, item); }); return roleList; } List<Long> list = (List<Long>) cacheObject.getValue(); List<Role> menuList = list.stream().map(this::getByIdCache) .filter(Objects::nonNull).collect(Collectors.toList()); return menuList; }
Example 2
Source File: ResourceServiceImpl.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
/** * 查询用户的可用资源 * * 注意:什么地方需要清除 USER_MENU 缓存 * 给用户重新分配角色时, 角色重新分配资源/菜单时 * * @param resource * @return */ @Override public List<Resource> findVisibleResource(ResourceQueryDTO resource) { //1, 先查 cache,cache中没有就执行回调查询DB,并设置到缓存 String userResourceKey = key(resource.getUserId()); List<Resource> visibleResource = new ArrayList<>(); CacheObject cacheObject = cacheChannel.get(CacheKey.USER_RESOURCE, userResourceKey, (key) -> { visibleResource.addAll(baseMapper.findVisibleResource(resource)); return visibleResource.stream().mapToLong(Resource::getId).boxed().collect(Collectors.toList()); }); //cache 和 db 都没有时直接返回 if (cacheObject.getValue() == null) { return Collections.emptyList(); } if (!visibleResource.isEmpty()) { visibleResource.forEach((r) -> { String menuKey = key(r.getId()); cacheChannel.set(RESOURCE, menuKey, r); }); return resourceListFilterGroup(resource.getMenuId(), visibleResource); } // 若list里面的值过多,而资源又均没有缓存(或者缓存击穿),则这里的效率并不高 List<Long> list = (List<Long>) cacheObject.getValue(); List<Resource> resourceList = list.stream().map(this::getByIdCache).filter(Objects::nonNull).collect(Collectors.toList()); if (resource.getMenuId() == null) { return resourceList; } // 根据查询条件过滤数据 return resourceListFilterGroup(resource.getMenuId(), visibleResource); }
Example 3
Source File: UserTokenServiceImpl.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
/** * 标记上一个token为被T状态 * * @param user */ private void evictPreviousToken(CacheObject user) { if (user.getValue() != null) { String previousToken = (String) user.getValue(); channel.set(CacheKey.TOKEN_USER_ID, CacheKey.buildKey(previousToken), BizConstant.LOGIN_STATUS); super.remove(Wraps.<UserToken>lbQ().eq(UserToken::getToken, previousToken)); } }
Example 4
Source File: J2CacheGeneralDataRegion.java From J2Cache with Apache License 2.0 | 5 votes |
@Override public Object get(Object key) throws CacheException { LOG.debugf("key: %s", key); if (key == null) { return null; } else { CacheObject value = getCache().get(key); if (value == null) { LOG.debugf("value for key %s is null", key); return null; } else { return value.getValue(); } } }
Example 5
Source File: J2CacheCache.java From J2Cache with Apache License 2.0 | 5 votes |
@Override protected Object lookup(Object key) { CacheObject cacheObject = cacheChannel.get(j2CacheName, String.valueOf(key), false); if(cacheObject.rawValue() != null && cacheObject.rawValue().getClass().equals(NullObject.class) && super.isAllowNullValues()) { return NullValue.INSTANCE; } return cacheObject.getValue(); }
Example 6
Source File: J2CacheCache.java From J2Cache with Apache License 2.0 | 5 votes |
@Override protected Object lookup(Object key) { CacheObject cacheObject = cacheChannel.get(j2CacheName, String.valueOf(key), false); if(cacheObject.rawValue() != null && cacheObject.rawValue().getClass().equals(NullObject.class) && super.isAllowNullValues()) { return NullValue.INSTANCE; } return cacheObject.getValue(); }
Example 7
Source File: J2Cache.java From t-io with Apache License 2.0 | 5 votes |
@Override public Serializable _get(String key) { CacheChannel cache = getChannel(); CacheObject cacheObject = cache.get(cacheName, key); if (cacheObject != null) { return (Serializable) cacheObject.getValue(); } return null; }
Example 8
Source File: J2CacheCache.java From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
@Override protected Object lookup(Object key) { CacheObject cacheObject = cacheChannel.get(j2CacheName, String.valueOf(key)); if (cacheObject.rawValue() != null && cacheObject.rawValue().getClass().equals(NullObject.class) && super.isAllowNullValues()) { return NullValue.INSTANCE; } return cacheObject.getValue(); }
Example 9
Source File: TransactionalJ2CacheEntityRegionAccessStrategy.java From J2Cache with Apache License 2.0 | 4 votes |
@Override public Object get(Object key, long txTimestamp) throws CacheException { final CacheObject element = cache.get(key); return element == null ? null : element.getValue(); }
Example 10
Source File: TransactionalJ2CacheNaturalIdRegionAccessStrategy.java From J2Cache with Apache License 2.0 | 4 votes |
@Override public Object get(Object key, long txTimestamp) throws CacheException { final CacheObject element = cache.get(key); return element == null ? null : element.getValue(); }
Example 11
Source File: J2cacheImpl.java From jboot with Apache License 2.0 | 4 votes |
@Override public <T> T get(String cacheName, Object key) { CacheObject cacheObject = J2Cache.getChannel().get(cacheName, key.toString(), false); return cacheObject != null ? (T) cacheObject.getValue() : null; }
Example 12
Source File: J2CacheTransactionalDataRegion.java From J2Cache with Apache License 2.0 | 4 votes |
public final Object get(Object key) { CacheObject object = this.getCache().get(key); return object != null ? object.getValue() : null; }
Example 13
Source File: TransactionalJ2CacheNaturalIdRegionAccessStrategy.java From J2Cache with Apache License 2.0 | 4 votes |
@Override public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException { final CacheObject element = cache.get(key); return element == null ? null : element.getValue(); }
Example 14
Source File: LoginLogServiceImpl.java From zuihou-admin-boot with Apache License 2.0 | 4 votes |
@Override public List<Map<String, Object>> findByOperatingSystem() { CacheObject cacheObject = this.cache.get(CacheKey.LOGIN_LOG_SYSTEM, CacheKey.buildTenantKey(), (key) -> this.baseMapper.findByOperatingSystem()); return (List<Map<String, Object>>) cacheObject.getValue(); }
Example 15
Source File: LoginLogServiceImpl.java From zuihou-admin-boot with Apache License 2.0 | 4 votes |
@Override public List<Map<String, Object>> findByBrowser() { CacheObject cacheObject = this.cache.get(CacheKey.LOGIN_LOG_BROWSER, CacheKey.buildTenantKey(), (key) -> this.baseMapper.findByBrowser()); return (List<Map<String, Object>>) cacheObject.getValue(); }
Example 16
Source File: LoginLogServiceImpl.java From zuihou-admin-boot with Apache License 2.0 | 4 votes |
@Override public List<Map<String, Object>> findLastTenDaysVisitCount(String account) { LocalDate tenDays = LocalDate.now().plusDays(-9); CacheObject cacheObject = this.cache.get(CacheKey.LOGIN_LOG_TEN_DAY, CacheKey.buildTenantKey(tenDays, account), (key) -> this.baseMapper.findLastTenDaysVisitCount(tenDays, account)); return (List<Map<String, Object>>) cacheObject.getValue(); }
Example 17
Source File: LoginLogServiceImpl.java From zuihou-admin-boot with Apache License 2.0 | 4 votes |
@Override public Long findTodayIp() { LocalDate now = LocalDate.now(); CacheObject cacheObject = this.cache.get(CacheKey.LOGIN_LOG_TODAY_IP, CacheKey.buildTenantKey(now), (key) -> this.baseMapper.findTodayIp(now)); return (Long) cacheObject.getValue(); }
Example 18
Source File: LoginLogServiceImpl.java From zuihou-admin-boot with Apache License 2.0 | 4 votes |
@Override public Long findTodayVisitCount() { LocalDate now = LocalDate.now(); CacheObject cacheObject = this.cache.get(CacheKey.LOGIN_LOG_TODAY, CacheKey.buildTenantKey(now), (key) -> this.baseMapper.findTodayVisitCount(now)); return (Long) cacheObject.getValue(); }
Example 19
Source File: LoginLogServiceImpl.java From zuihou-admin-cloud with Apache License 2.0 | 4 votes |
@Override public Long findTodayIp() { LocalDate now = LocalDate.now(); CacheObject cacheObject = this.cache.get(CacheKey.LOGIN_LOG_TODAY_IP, CacheKey.buildTenantKey(now), (key) -> this.baseMapper.findTodayIp(now)); return (Long) cacheObject.getValue(); }
Example 20
Source File: LoginLogServiceImpl.java From zuihou-admin-cloud with Apache License 2.0 | 4 votes |
@Override public List<Map<String, Object>> findByOperatingSystem() { CacheObject cacheObject = this.cache.get(CacheKey.LOGIN_LOG_SYSTEM, CacheKey.buildTenantKey(), (key) -> this.baseMapper.findByOperatingSystem()); return (List<Map<String, Object>>) cacheObject.getValue(); }