1 package org.onap.cps.api.impl;
3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2020 Pantheon.tech
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 import com.google.errorprone.annotations.CanIgnoreReturnValue;
23 import org.onap.cps.spi.CpsModulePersistenceService;
24 import org.onap.cps.yang.YangTextSchemaSourceSet;
25 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.cache.annotation.CacheConfig;
28 import org.springframework.cache.annotation.CachePut;
29 import org.springframework.cache.annotation.Cacheable;
30 import org.springframework.stereotype.Service;
33 * Provides cached YangTextSchemaSourceSet.
36 @CacheConfig(cacheNames = {"yangSchema"})
37 public class YangTextSchemaSourceSetCache {
40 private CpsModulePersistenceService cpsModulePersistenceService;
43 * Cache YangTextSchemaSourceSet.
45 * @param dataspaceName dataspace name
46 * @param schemaSetName schema set name
47 * @return YangTextSchemaSourceSet
49 @Cacheable(key = "#p0.concat('-').concat(#p1)")
50 public YangTextSchemaSourceSet get(final String dataspaceName, final String schemaSetName) {
51 final Map<String, String> yangResourceNameToContent =
52 cpsModulePersistenceService.getYangSchemaResources(dataspaceName, schemaSetName);
53 return YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent);
57 * Updates cache YangTextSchemaSourceSet.
59 * @param dataspaceName dataspace name
60 * @param schemaSetName schema set name
61 * @param yangTextSchemaSourceSet yangTextSchemaSourceSet
62 * @return YangTextSchemaSourceSet
64 @CachePut(key = "#p0.concat('-').concat(#p1)")
66 public YangTextSchemaSourceSet updateCache(final String dataspaceName, final String schemaSetName,
67 final YangTextSchemaSourceSet yangTextSchemaSourceSet) {
68 return yangTextSchemaSourceSet;