Skip to content

Commit

Permalink
fix: sdk keys cache evict
Browse files Browse the repository at this point in the history
  • Loading branch information
jianggang committed Aug 25, 2022
1 parent 3eeea34 commit 8f7c10e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ public class EnvironmentService {

private static final String LIMITER_TOGGLE_KEY = "FeatureProbe_env_limiter";

public static final String ALL_SDK_KEYS_CACHE_KEY = ServerService.ALL_SDK_KEYS_CACHE_KEY;

@Transactional(rollbackFor = Exception.class)
@CacheEvict(value="all_sdk_key_map", allEntries=true)
@CacheEvict(cacheNames="all_sdk_key_map", key = "#root.target.ALL_SDK_KEYS_CACHE_KEY")
public EnvironmentResponse create(String projectKey, EnvironmentCreateRequest createRequest) {
validateLimit(projectKey);
Project project = projectRepository.findByKey(projectKey).get();
Expand All @@ -68,6 +70,7 @@ public EnvironmentResponse create(String projectKey, EnvironmentCreateRequest cr
}

@Transactional(rollbackFor = Exception.class)
@CacheEvict(cacheNames="all_sdk_key_map", key = "#root.target.ALL_SDK_KEYS_CACHE_KEY")
public EnvironmentResponse update(String projectKey, String environmentKey,
EnvironmentUpdateRequest updateRequest) {
Environment environment = environmentRepository.findByProjectKeyAndKey(projectKey, environmentKey).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ public class ProjectService {

private static final String LIMITER_TOGGLE_KEY = "FeatureProbe_project_limiter";

public static final String ALL_SDK_KEYS_CACHE_KEY = ServerService.ALL_SDK_KEYS_CACHE_KEY;

@Transactional(rollbackFor = Exception.class)
@CacheEvict(value="all_sdk_key_map", allEntries=true)
@CacheEvict(cacheNames="all_sdk_key_map", key = "#root.target.ALL_SDK_KEYS_CACHE_KEY")
public ProjectResponse create(ProjectCreateRequest createRequest) {
validateLimit();
return ProjectMapper.INSTANCE.entityToResponse(createProject(createRequest));
}

@Transactional(rollbackFor = Exception.class)
@CacheEvict(cacheNames="all_sdk_key_map", key = "#root.target.ALL_SDK_KEYS_CACHE_KEY")
public ProjectResponse update(String projectKey, ProjectUpdateRequest updateRequest) {
Project project = projectRepository.findByKey(projectKey).get();
if (!StringUtils.equals(project.getName(), updateRequest.getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public class ServerService {
@PersistenceContext
public EntityManager entityManager;

@Cacheable(value="all_sdk_key_map")
public static final String ALL_SDK_KEYS_CACHE_KEY = "all_sdk_key_map";

@Cacheable(cacheNames="all_sdk_key_map", key = "#root.target.ALL_SDK_KEYS_CACHE_KEY")
public SdkKeyResponse queryAllSdkKeys() {
SdkKeyResponse sdkKeyResponse = new SdkKeyResponse();
List<Environment> environments = environmentRepository.findAll();
Expand Down

0 comments on commit 8f7c10e

Please sign in to comment.