001package org.cache2k; 002 003/* 004 * #%L 005 * cache2k api only package 006 * %% 007 * Copyright (C) 2000 - 2014 headissue GmbH, Munich 008 * %% 009 * This program is free software: you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as 011 * published by the Free Software Foundation, either version 3 of the 012 * License, or (at your option) any later version. 013 * 014 * This program is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public 020 * License along with this program. If not, see 021 * <http://www.gnu.org/licenses/gpl-3.0.html>. 022 * #L% 023 */ 024 025/** 026 * Cache configuration. Adheres to bean standard. 027 * 028 * @author Jens Wilke; created: 2013-06-25 029 */ 030public class CacheConfig { 031 032 private String name; 033 private Class<?> keyType; 034 private Class<?> valueType; 035 private Class<?> entryType; 036 private Class<?> implementation; 037 private int maxSize = 2000; 038 private int maxSizeHighBound = Integer.MAX_VALUE; 039 private int maxSizeLowBound = 0; 040 private boolean backgroundRefresh = true; 041 private int expirySeconds = 10 * 60; 042 private boolean keepDataAfterExpired = true; 043 044 public String getName() { 045 return name; 046 } 047 048 public void setName(String name) { 049 this.name = name; 050 } 051 052 public int getMaxSize() { 053 return maxSize; 054 } 055 056 public void setMaxSize(int maxSize) { 057 this.maxSize = maxSize; 058 } 059 060 public int getMaxSizeHighBound() { 061 return maxSizeHighBound; 062 } 063 064 public void setMaxSizeHighBound(int maxSizeHighBound) { 065 if (maxSize > maxSizeHighBound) { 066 maxSize = maxSizeHighBound; 067 } 068 this.maxSizeHighBound = maxSizeHighBound; 069 } 070 071 public int getMaxSizeLowBound() { 072 return maxSizeLowBound; 073 } 074 075 public void setMaxSizeLowBound(int maxSizeLowBound) { 076 if (maxSize < maxSizeLowBound) { 077 maxSize = maxSizeLowBound; 078 } 079 this.maxSizeLowBound = maxSizeLowBound; 080 } 081 082 public boolean isBackgroundRefresh() { 083 return backgroundRefresh; 084 } 085 086 public void setBackgroundRefresh(boolean backgroundRefresh) { 087 this.backgroundRefresh = backgroundRefresh; 088 } 089 090 public Class<?> getKeyType() { 091 return keyType; 092 } 093 094 public void setKeyType(Class<?> keyType) { 095 this.keyType = keyType; 096 } 097 098 public Class<?> getValueType() { 099 return valueType; 100 } 101 102 public Class<?> getEntryType() { 103 return entryType; 104 } 105 106 public void setEntryType(Class<?> entryType) { 107 this.entryType = entryType; 108 } 109 110 public void setValueType(Class<?> valueType) { 111 this.valueType = valueType; 112 } 113 114 public int getExpirySeconds() { 115 return expirySeconds; 116 } 117 118 /** 119 * Time to pass until an entry is expired and will not be returned by the cache any 120 * more. 0 means expiry is immediately. -1 or {@link Integer#MAX_VALUE} means 121 * no expiry. 122 */ 123 public void setExpirySeconds(int expirySeconds) { 124 this.expirySeconds = expirySeconds; 125 } 126 127 public boolean isKeepDataAfterExpired() { 128 return keepDataAfterExpired; 129 } 130 131 /** 132 * Expired data is kept in the cache until the entry is evicted by the replacement 133 * algorithm. This consumes memory, but if the data needs to be fetched again previous 134 * data can be used by the cache source for optimizing, e.g. for a get if-modified-since. 135 */ 136 public void setKeepDataAfterExpired(boolean v) { 137 this.keepDataAfterExpired = v; 138 } 139 140 public Class<?> getImplementation() { 141 return implementation; 142 } 143 144 public void setImplementation(Class<?> cacheImplementation) { 145 this.implementation = cacheImplementation; 146 } 147 148}