KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > template > cache > CmsTimeout


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/template/cache/CmsTimeout.java,v $
3 * Date : $Date: 2005/05/17 13:47:27 $
4 * Version: $Revision: 1.1 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * For further information about OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */

28
29 package com.opencms.template.cache;
30 /**
31  * This class is used in the CmsCacheDirectives. If an element can be cached for
32  * a specific time, a CmsTimeout must be set. It is planned to have diffrent modi
33  * for this Class. In this moment we have only one mode:
34  *
35  * 0: use the constructor with int x. It means the element has to be new generated
36  * at 00:00 and then every x minutes.
37  *
38  * @author Hanjo Riege
39  * @version 1.0
40  *
41  * @deprecated Will not be supported past the OpenCms 6 release.
42  */

43
44 public class CmsTimeout {
45
46     // USED FOR MODUS 0
47
// this is time a element is valid (in millisec)
48
private long m_timeinterval;
49     // here is the time 0:00 for this day, it is recalculated only if needed
50
private static long m_daystart = 0;
51     // 24 hours in millisec (24*60*60*1000)
52
private static final long C_24_HOURS = 86400000;
53
54     // Constructor for modus 0
55
public CmsTimeout(int minutes) {
56         m_timeinterval = minutes * 60 * 1000;
57     }
58
59     /**
60      * The proxy cache is set for 300 seconds. If this Timeout shows problems with
61      * this interval the method returns false. In modus 0 <=> timeintervals < 300.
62      * @return false if the element is not proxycacheable.
63      */

64     public boolean isProxyCacheable(){
65
66         // MODUS 0
67
if(m_timeinterval < 5*60*1000){
68             return false;
69         }
70
71         return true;
72     }
73
74     /**
75      * Returns the last time when the element had to be new generated.
76      *
77      * @return last change time.
78      */

79     public long getLastChange(){
80         long time = System.currentTimeMillis();
81
82         // MODUS 0 (the only one for now)
83

84         // the time since 0:00 (should be < 24 hours)
85
long daytime = time - m_daystart;
86         if ( daytime > C_24_HOURS) {
87             // the daystart has to be recalculated
88
java.util.Calendar JavaDoc timeCal = java.util.Calendar.getInstance();
89             timeCal.set(java.util.Calendar.HOUR_OF_DAY, 0);
90             timeCal.set(java.util.Calendar.SECOND, 0);
91             timeCal.set(java.util.Calendar.MINUTE, 0);
92             timeCal.set(java.util.Calendar.MILLISECOND, 0);
93             m_daystart = timeCal.getTime().getTime();
94             daytime = time - m_daystart;
95         }
96         return m_daystart + (daytime - (daytime % m_timeinterval));
97
98     }
99 }
Popular Tags