Merge of new rebased code
[appc.git] / appc-common / src / main / java / org / openecomp / appc / cache / impl / MetadataCacheImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.cache.impl;
23
24 import org.openecomp.appc.cache.CacheStrategies;
25 import org.openecomp.appc.cache.CacheStrategy;
26 import org.openecomp.appc.cache.MetadataCache;
27
28
29 public class MetadataCacheImpl<K,V> implements MetadataCache<K,V> {
30
31     private CacheStrategy strategy;
32
33     MetadataCacheImpl(){
34         this(CacheStrategies.LRU);
35     }
36
37     MetadataCacheImpl(CacheStrategies strategy){
38         this.strategy = initializeStrategy(strategy);
39     }
40
41     private CacheStrategy initializeStrategy(CacheStrategies strategy) {
42         switch (strategy){
43             case LRU:
44                 return new LRUCache<>(50);
45         }
46         return null;
47     }
48
49     @Override
50     public V getObject(K key) {
51         return (V)strategy.getObject(key);
52     }
53
54     @Override
55     public void putObject(K key, V value) {
56         strategy.putObject(key,value);
57     }
58 }