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.yang.YangTextSchemaSourceSet;
28 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.cache.annotation.CacheConfig;
31 import org.springframework.cache.annotation.CacheEvict;
32 import org.springframework.cache.annotation.CachePut;
33 import org.springframework.cache.annotation.Cacheable;
34 import org.springframework.stereotype.Service;
37 * Provides cached YangTextSchemaSourceSet.
40 @CacheConfig(cacheNames = {"yangSchema"})
41 public class YangTextSchemaSourceSetCache {
44 private CpsModulePersistenceService cpsModulePersistenceService;
47 * Cache YangTextSchemaSourceSet.
49 * @param dataspaceName dataspace name
50 * @param schemaSetName schema set name
51 * @return YangTextSchemaSourceSet
53 @Cacheable(key = "#p0.concat('-').concat(#p1)")
54 public YangTextSchemaSourceSet get(final String dataspaceName, final String schemaSetName) {
55 final Map<String, String> yangResourceNameToContent =
56 cpsModulePersistenceService.getYangSchemaResources(dataspaceName, schemaSetName);
57 return YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent);
61 * Updates cache YangTextSchemaSourceSet.
63 * @param dataspaceName dataspace name
64 * @param schemaSetName schema set name
65 * @param yangTextSchemaSourceSet yangTextSchemaSourceSet
66 * @return YangTextSchemaSourceSet
68 @CachePut(key = "#p0.concat('-').concat(#p1)")
70 public YangTextSchemaSourceSet updateCache(final String dataspaceName, final String schemaSetName,
71 final YangTextSchemaSourceSet yangTextSchemaSourceSet) {
72 return yangTextSchemaSourceSet;
77 * Remove the cached value for the given dataspace and schema-set.
79 * @param dataspaceName dataspace name
80 * @param schemaSetName schema set name
82 @CacheEvict(key = "#p0.concat('-').concat(#p1)")
83 public void removeFromCache(final String dataspaceName, final String schemaSetName) {
84 // Spring provides implementation for removing object from cache