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