2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Pantheon.tech
4 * Modifications Copyright (C) 2022 Bell Canada
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
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.api.impl;
24 import com.google.errorprone.annotations.CanIgnoreReturnValue;
26 import org.onap.cps.spi.CpsModulePersistenceService;
27 import org.onap.cps.utils.CpsValidator;
28 import org.onap.cps.yang.YangTextSchemaSourceSet;
29 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.cache.annotation.CacheConfig;
32 import org.springframework.cache.annotation.CacheEvict;
33 import org.springframework.cache.annotation.CachePut;
34 import org.springframework.cache.annotation.Cacheable;
35 import org.springframework.stereotype.Service;
38 * Provides cached YangTextSchemaSourceSet.
41 @CacheConfig(cacheNames = {"yangSchema"})
42 public class YangTextSchemaSourceSetCache {
45 private CpsModulePersistenceService cpsModulePersistenceService;
48 * Cache YangTextSchemaSourceSet.
50 * @param dataspaceName dataspace name
51 * @param schemaSetName schema set name
52 * @return YangTextSchemaSourceSet
54 @Cacheable(key = "#p0.concat('-').concat(#p1)")
55 public YangTextSchemaSourceSet get(final String dataspaceName, final String schemaSetName) {
56 CpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
57 final Map<String, String> yangResourceNameToContent =
58 cpsModulePersistenceService.getYangSchemaResources(dataspaceName, schemaSetName);
59 return YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent);
63 * Updates cache YangTextSchemaSourceSet.
65 * @param dataspaceName dataspace name
66 * @param schemaSetName schema set name
67 * @param yangTextSchemaSourceSet yangTextSchemaSourceSet
68 * @return YangTextSchemaSourceSet
70 @CachePut(key = "#p0.concat('-').concat(#p1)")
72 public YangTextSchemaSourceSet updateCache(final String dataspaceName, final String schemaSetName,
73 final YangTextSchemaSourceSet yangTextSchemaSourceSet) {
74 CpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
75 return yangTextSchemaSourceSet;
80 * Remove the cached value for the given dataspace and schema-set.
82 * @param dataspaceName dataspace name
83 * @param schemaSetName schema set name
85 @CacheEvict(key = "#p0.concat('-').concat(#p1)")
86 public void removeFromCache(final String dataspaceName, final String schemaSetName) {
87 CpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
88 // Spring provides implementation for removing object from cache