1 25 26 28 package de.nava.informa.utils; 29 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 33 import de.nava.informa.core.ChannelIF; 34 35 38 public class RSS100Settings implements CacheSettingsIF { 39 40 private static Log logger = LogFactory.getLog(RSS100Settings.class); 41 42 private long defaultTtl = DEFAULT_TTL; 43 44 public void setDefaultTtl(long defaultTtl) { 45 this.defaultTtl = defaultTtl; 46 } 47 48 52 public long getTtl(ChannelIF channel, long ttlInMs) { 53 String updatePeriod = channel.getUpdatePeriod(); 54 int updateFrequency = channel.getUpdateFrequency(); 55 56 if (updatePeriod == null) { 57 if (ttlInMs > MINIMAL_TTL) 58 return ttlInMs; 59 return this.defaultTtl; 60 } 61 62 if (updateFrequency < 0) { 63 updateFrequency = 1; 64 } 65 66 long msInPeriod; 67 68 if (updatePeriod.equals(ChannelIF.UPDATE_HOURLY)) { 69 msInPeriod = MILLISECONDS_IN_HOUR; 70 } else if (updatePeriod.equals(ChannelIF.UPDATE_DAILY)) { 71 msInPeriod = MILLISECONDS_IN_DAY; 72 } else if (updatePeriod.equals(ChannelIF.UPDATE_MONTHLY)) { 73 msInPeriod = MILLISECONDS_IN_MONTH; 74 } else if (updatePeriod.equals(ChannelIF.UPDATE_YEARLY)) { 75 msInPeriod = MILLISECONDS_IN_YEAR; 76 } else { 77 throw new IllegalArgumentException ("updatePeriod " + updatePeriod + 78 " is not valid"); 79 } 80 81 long timeToExpire = msInPeriod / updateFrequency; 82 83 if (ttlInMs > timeToExpire) { 84 return ttlInMs; 85 } 86 return timeToExpire; 87 } 88 89 } | Popular Tags |