001package com.avaje.ebean.cache; 002 003import com.avaje.ebean.annotation.CacheQueryTuning; 004import com.avaje.ebean.annotation.CacheBeanTuning; 005 006/** 007 * Options for controlling a cache. 008 */ 009public class ServerCacheOptions { 010 011 private int maxSize; 012 private int maxIdleSecs; 013 private int maxSecsToLive; 014 private int trimFrequency; 015 016 /** 017 * Construct with no set options. 018 */ 019 public ServerCacheOptions() { 020 021 } 022 023 /** 024 * Create from the cacheTuning deployment annotation. 025 */ 026 public ServerCacheOptions(CacheBeanTuning tuning) { 027 this.maxSize = tuning.maxSize(); 028 this.maxIdleSecs = tuning.maxIdleSecs(); 029 this.maxSecsToLive = tuning.maxSecsToLive(); 030 this.trimFrequency = tuning.trimFrequency(); 031 } 032 033 /** 034 * Create from the cacheTuning deployment annotation. 035 */ 036 public ServerCacheOptions(CacheQueryTuning cacheTuning) { 037 this.maxSize = cacheTuning.maxSize(); 038 this.maxIdleSecs = cacheTuning.maxIdleSecs(); 039 this.maxSecsToLive = cacheTuning.maxSecsToLive(); 040 this.trimFrequency = cacheTuning.trimFrequency(); 041 } 042 043 /** 044 * Apply any settings from the default settings that have not already been 045 * specifically set. 046 */ 047 public void applyDefaults(ServerCacheOptions defaults) { 048 if (maxSize == 0) { 049 maxSize = defaults.getMaxSize(); 050 } 051 if (maxIdleSecs == 0) { 052 maxIdleSecs = defaults.getMaxIdleSecs(); 053 } 054 if (maxSecsToLive == 0) { 055 maxSecsToLive = defaults.getMaxSecsToLive(); 056 } 057 if (trimFrequency == 0) { 058 trimFrequency = defaults.getTrimFrequency(); 059 } 060 } 061 062 /** 063 * Return a copy of this object. 064 */ 065 public ServerCacheOptions copy() { 066 067 ServerCacheOptions copy = new ServerCacheOptions(); 068 copy.maxSize = maxSize; 069 copy.maxIdleSecs = maxIdleSecs; 070 copy.maxSecsToLive = maxSecsToLive; 071 copy.trimFrequency = trimFrequency; 072 return copy; 073 } 074 075 /** 076 * Return the maximum cache size. 077 */ 078 public int getMaxSize() { 079 return maxSize; 080 } 081 082 /** 083 * Set the maximum cache size. 084 */ 085 public void setMaxSize(int maxSize) { 086 this.maxSize = maxSize; 087 } 088 089 /** 090 * Return the maximum idle time. 091 */ 092 public int getMaxIdleSecs() { 093 return maxIdleSecs; 094 } 095 096 /** 097 * Set the maximum idle time. 098 */ 099 public void setMaxIdleSecs(int maxIdleSecs) { 100 this.maxIdleSecs = maxIdleSecs; 101 } 102 103 /** 104 * Return the maximum time to live. 105 */ 106 public int getMaxSecsToLive() { 107 return maxSecsToLive; 108 } 109 110 /** 111 * Set the maximum time to live. 112 */ 113 public void setMaxSecsToLive(int maxSecsToLive) { 114 this.maxSecsToLive = maxSecsToLive; 115 } 116 117 /** 118 * Return the trim frequency in seconds. 119 */ 120 public int getTrimFrequency() { 121 return trimFrequency; 122 } 123 124 /** 125 * Set the trim frequency in seconds. 126 */ 127 public void setTrimFrequency(int trimFrequency) { 128 this.trimFrequency = trimFrequency; 129 } 130}