summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main/java/org/onap
diff options
context:
space:
mode:
authorClaudio David Gasparini <claudio.gasparini@pantheon.tech>2021-01-13 19:12:25 +0100
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>2021-01-21 18:52:55 +0100
commit1b8a4dd237077944df7bef5fa04c412da01029f0 (patch)
tree5b3d9f62011f82b0d78c9a43a1363de635af21f8 /cps-service/src/main/java/org/onap
parentcd9f368b1f3c5e25e17e21649e582d84a909ac79 (diff)
Introduce caffeine cache
Issue-ID: CPS-163 Signed-off-by: Claudio David Gasparini <claudio.gasparini@pantheon.tech> Change-Id: Iff9b831c2d895d82aff419f60a8dd86a38b545d0
Diffstat (limited to 'cps-service/src/main/java/org/onap')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java31
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java70
-rw-r--r--cps-service/src/main/java/org/onap/cps/config/CacheConfig.java29
3 files changed, 113 insertions, 17 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
index eac28a9f09..427ddd6c6f 100644
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
@@ -20,7 +20,6 @@
package org.onap.cps.api.impl;
import java.util.Map;
-import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.spi.CascadeDeleteAllowed;
import org.onap.cps.spi.CpsModulePersistenceService;
@@ -28,34 +27,32 @@ import org.onap.cps.spi.model.SchemaSet;
import org.onap.cps.yang.YangTextSchemaSourceSet;
import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
-@Component("CpsModuleServiceImpl")
+@Service("CpsModuleServiceImpl")
public class CpsModuleServiceImpl implements CpsModuleService {
@Autowired
private CpsModulePersistenceService cpsModulePersistenceService;
+ @Autowired
+ private YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
+
@Override
public void createSchemaSet(final String dataspaceName, final String schemaSetName,
- final Map<String, String> yangResourcesNameToContentMap) {
-
- YangTextSchemaSourceSetBuilder.validate(yangResourcesNameToContentMap);
- cpsModulePersistenceService
- .storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap);
+ final Map<String, String> yangResourcesNameToContentMap) {
+ final YangTextSchemaSourceSet yangTextSchemaSourceSet
+ = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap);
+ cpsModulePersistenceService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap);
+ yangTextSchemaSourceSetCache.updateCache(dataspaceName, schemaSetName, yangTextSchemaSourceSet);
}
@Override
public SchemaSet getSchemaSet(final String dataspaceName, final String schemaSetName) {
- final Map<String, String> yangResourceNameToContent =
- cpsModulePersistenceService.getYangSchemaResources(dataspaceName, schemaSetName);
- final YangTextSchemaSourceSet yangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder
- .of(yangResourceNameToContent);
- return SchemaSet.builder()
- .name(schemaSetName)
- .dataspaceName(dataspaceName)
- .moduleReferences(yangTextSchemaSourceSet.getModuleReferences())
- .build();
+ final YangTextSchemaSourceSet yangTextSchemaSourceSet = yangTextSchemaSourceSetCache
+ .get(dataspaceName, schemaSetName);
+ return SchemaSet.builder().name(schemaSetName).dataspaceName(dataspaceName)
+ .moduleReferences(yangTextSchemaSourceSet.getModuleReferences()).build();
}
@Override
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java b/cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java
new file mode 100644
index 0000000000..af16727f19
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java
@@ -0,0 +1,70 @@
+package org.onap.cps.api.impl;
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Pantheon.tech
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import java.util.Map;
+import org.onap.cps.spi.CpsModulePersistenceService;
+import org.onap.cps.yang.YangTextSchemaSourceSet;
+import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheConfig;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+/**
+ * Provides cached YangTextSchemaSourceSet.
+ */
+@Service
+@CacheConfig(cacheNames = {"yangSchema"})
+public class YangTextSchemaSourceSetCache {
+
+ @Autowired
+ private CpsModulePersistenceService cpsModulePersistenceService;
+
+ /**
+ * Cache YangTextSchemaSourceSet.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schema set name
+ * @return YangTextSchemaSourceSet
+ */
+ @Cacheable(key = "#p0.concat('-').concat(#p1)")
+ public YangTextSchemaSourceSet get(final String dataspaceName, final String schemaSetName) {
+ final Map<String, String> yangResourceNameToContent =
+ cpsModulePersistenceService.getYangSchemaResources(dataspaceName, schemaSetName);
+ return YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent);
+ }
+
+ /**
+ * Updates cache YangTextSchemaSourceSet.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schema set name
+ * @param yangTextSchemaSourceSet yangTextSchemaSourceSet
+ * @return YangTextSchemaSourceSet
+ */
+ @CachePut(key = "#p0.concat('-').concat(#p1)")
+ @CanIgnoreReturnValue
+ public YangTextSchemaSourceSet updateCache(final String dataspaceName, final String schemaSetName,
+ final YangTextSchemaSourceSet yangTextSchemaSourceSet) {
+ return yangTextSchemaSourceSet;
+ }
+}
diff --git a/cps-service/src/main/java/org/onap/cps/config/CacheConfig.java b/cps-service/src/main/java/org/onap/cps/config/CacheConfig.java
new file mode 100644
index 0000000000..4441e4f2a1
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/config/CacheConfig.java
@@ -0,0 +1,29 @@
+package org.onap.cps.config;
+
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Pantheon.tech
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@EnableCaching
+public class CacheConfig {
+
+} \ No newline at end of file