Search in sources :

Example 16 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey in project albedo by somowhere.

the class TenantServiceImpl method getByCode.

/**
 * tenant_name:{tenantCode} -> id 只存租户的id,然后根据id再次查询缓存,这样子的好处是,删除或者修改租户信息时,只需要根据id淘汰缓存即可
 * 缺点就是 每次查询,需要多查一次缓存
 *
 * @param tenant
 * @return
 */
@Override
public Tenant getByCode(String tenant) {
    Function<CacheKey, Object> loader = (k) -> getObj(Wraps.<Tenant>lbQ().select(Tenant::getId).eq(Tenant::getCode, tenant), Convert::toLong);
    CacheKey cacheKey = new TenantCodeCacheKeyBuilder().key(tenant);
    return getByKey(cacheKey, loader);
}
Also used : Wraps(com.albedo.java.plugins.database.mybatis.conditions.Wraps) TenantConnectDto(com.albedo.java.modules.tenant.domain.dto.TenantConnectDto) ArgumentAssert(com.albedo.java.common.core.util.ArgumentAssert) InitSystemContext(com.albedo.java.modules.tenant.strategy.InitSystemContext) Tenant(com.albedo.java.modules.tenant.domain.Tenant) TenantService(com.albedo.java.modules.tenant.service.TenantService) RequiredArgsConstructor(lombok.RequiredArgsConstructor) BeanUtil(com.albedo.java.common.core.util.BeanUtil) CacheKeyBuilder(com.albedo.java.common.core.cache.model.CacheKeyBuilder) TenantRepository(com.albedo.java.modules.tenant.repository.TenantRepository) Function(java.util.function.Function) TenantDto(com.albedo.java.modules.tenant.domain.dto.TenantDto) TenantCacheKeyBuilder(com.albedo.java.modules.tenant.TenantCacheKeyBuilder) TenantTypeEnum(com.albedo.java.modules.tenant.enumeration.TenantTypeEnum) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Service(org.springframework.stereotype.Service) AbstractDataCacheServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.AbstractDataCacheServiceImpl) Convert(cn.hutool.core.convert.Convert) AppendixService(com.albedo.java.modules.file.service.AppendixService) TenantStatusEnum(com.albedo.java.modules.tenant.enumeration.TenantStatusEnum) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) TenantCodeCacheKeyBuilder(com.albedo.java.modules.tenant.TenantCodeCacheKeyBuilder) Transactional(org.springframework.transaction.annotation.Transactional) TenantCodeCacheKeyBuilder(com.albedo.java.modules.tenant.TenantCodeCacheKeyBuilder) Tenant(com.albedo.java.modules.tenant.domain.Tenant) Convert(cn.hutool.core.convert.Convert) CacheKey(com.albedo.java.common.core.cache.model.CacheKey)

Example 17 with CacheKey

use of com.albedo.java.common.core.cache.model.CacheKey in project albedo by somowhere.

the class AbstractCacheServiceImpl method setCache.

protected void setCache(T model) {
    Object id = getId(model);
    if (id != null) {
        CacheKey key = cacheKeyBuilder().key(id);
        cacheOps.set(key, model);
    }
}
Also used : CacheKey(com.albedo.java.common.core.cache.model.CacheKey)

Aggregations

CacheKey (com.albedo.java.common.core.cache.model.CacheKey)17 Transactional (org.springframework.transaction.annotation.Transactional)12 Service (org.springframework.stereotype.Service)8 RequiredArgsConstructor (lombok.RequiredArgsConstructor)6 Convert (cn.hutool.core.convert.Convert)5 StrUtil (cn.hutool.core.util.StrUtil)5 CacheOps (com.albedo.java.plugins.cache.repository.CacheOps)5 List (java.util.List)5 ArgumentAssert (com.albedo.java.common.core.util.ArgumentAssert)4 ParameterKeyCacheKeyBuilder (com.albedo.java.modules.sys.cache.ParameterKeyCacheKeyBuilder)4 UserVo (com.albedo.java.modules.sys.domain.vo.UserVo)4 Wraps (com.albedo.java.plugins.database.mybatis.conditions.Wraps)4 LocalDate (java.time.LocalDate)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4 DatePattern (cn.hutool.core.date.DatePattern)3 LocalDateTimeUtil (cn.hutool.core.date.LocalDateTimeUtil)3 CacheKeyBuilder (com.albedo.java.common.core.cache.model.CacheKeyBuilder)3 MapHelper (com.albedo.java.common.core.util.MapHelper)3 ParameterUpdateEvent (com.albedo.java.common.event.listener.ParameterUpdateEvent)3