View | Details | Raw Unified | Return to bug 18499
Collapse All | Expand All

(-)src/org/apache/taglibs/cache/CacheTag.java (-1 / +13 lines)
Lines 72-77 Link Here
72
72
73
    private String nameExpr;				// tag attribute
73
    private String nameExpr;				// tag attribute
74
    private String keyExpr;				// tag attribute
74
    private String keyExpr;				// tag attribute
75
    private int lifetime;                               // tag attribute 
75
76
76
    private int scope;					// parsed tag attribute
77
    private int scope;					// parsed tag attribute
77
    private String name, key;				// parsed tag attribute
78
    private String name, key;				// parsed tag attribute
Lines 100-106 Link Here
100
	    s = "";
101
	    s = "";
101
          else
102
          else
102
            s = bodyContent.getString().trim();
103
            s = bodyContent.getString().trim();
103
          cache.put(key, s);
104
          if (lifetime == -1) 
105
            cache.put(key, s);
106
          else
107
            cache.put(key, s, lifetime);
104
        }
108
        }
105
        pageContext.getOut().write(s);
109
        pageContext.getOut().write(s);
106
      } catch (java.io.IOException ex) {
110
      } catch (java.io.IOException ex) {
Lines 133-138 Link Here
133
      this.keyExpr = keyExpr;
137
      this.keyExpr = keyExpr;
134
    }
138
    }
135
139
140
    public void setLifetime(String value) {
141
      try {
142
        lifetime = new Integer(value).intValue() * 1000;
143
      } catch (NumberFormatException nfe) {
144
        pageContext.getServletContext().log("invalid cache lifetime : "+value);
145
      }
146
    }
136
147
137
    //*********************************************************************
148
    //*********************************************************************
138
    // Constructor and initialization
149
    // Constructor and initialization
Lines 146-151 Link Here
146
      scope = PageContext.APPLICATION_SCOPE;
157
      scope = PageContext.APPLICATION_SCOPE;
147
      name = nameExpr = "";
158
      name = nameExpr = "";
148
      key = keyExpr = "";
159
      key = keyExpr = "";
160
      lifetime = -1;
149
    }
161
    }
150
    
162
    
151
163
(-)src/org/apache/taglibs/cache/LRUCache.java (-6 / +9 lines)
Lines 107-127 Link Here
107
   * Stores data associated with each cache entry.
107
   * Stores data associated with each cache entry.
108
   */
108
   */
109
  private class CacheEntry {
109
  private class CacheEntry {
110
    private long expiration;
110
    private long expiration = 0;
111
    private String value;
111
    private String value;
112
    private int size;
112
    private int size;
113
113
114
    public CacheEntry(String value) {
114
    public CacheEntry(String value, int ltime) {
115
      this.value = value;
115
      this.value = value;
116
      this.size = value.length();
116
      this.size = value.length();
117
      if (lifetime > 0) {
117
      if (ltime > 0) {
118
        this.expiration = (new Date()).getTime() + lifetime;
118
        this.expiration = (new Date()).getTime() + ltime;
119
      }
119
      }
120
    }
120
    }
121
    public String getValue() { return value; }
121
    public String getValue() { return value; }
122
    public long getSize() { return size; }
122
    public long getSize() { return size; }
123
    public boolean isExpired() { 
123
    public boolean isExpired() { 
124
      if (lifetime <= 0)
124
      if (expiration == 0)
125
        return false;
125
        return false;
126
      return (expiration < (new Date()).getTime());
126
      return (expiration < (new Date()).getTime());
127
    }
127
    }
Lines 157-162 Link Here
157
  }
157
  }
158
158
159
  public Object put(Object key, Object value) {
159
  public Object put(Object key, Object value) {
160
      return put(key, value, lifetime);
161
  }
162
  public Object put(Object key, Object value, int ltime) {
160
    if (!(value instanceof String))
163
    if (!(value instanceof String))
161
      throw new IllegalArgumentException(
164
      throw new IllegalArgumentException(
162
        "this Map only accepts Strings as values");
165
        "this Map only accepts Strings as values");
Lines 164-170 Link Here
164
    CacheEntry oldEntry = (CacheEntry) cache.get(key);
167
    CacheEntry oldEntry = (CacheEntry) cache.get(key);
165
    if (oldEntry != null)
168
    if (oldEntry != null)
166
      currentSize -= oldEntry.getSize();
169
      currentSize -= oldEntry.getSize();
167
    CacheEntry e = new CacheEntry((String) value);
170
    CacheEntry e = new CacheEntry((String) value, ltime);
168
    currentSize += e.getSize();
171
    currentSize += e.getSize();
169
    cache.put(key, e);
172
    cache.put(key, e);
170
    noteUsed(key);
173
    noteUsed(key);
(-)xml/cache.xml (+12 lines)
Lines 145-150 Link Here
145
        <availability>1.0</availability>
145
        <availability>1.0</availability>
146
      </attribute>
146
      </attribute>
147
147
148
      <attribute>
149
        <name>lifetime</name>
150
        <required>no</required>
151
        <rtexprvalue>yes</rtexprvalue>
152
        <type>int</type>
153
        <description>
154
	   The lifetime for this specific cache entry.
155
           In seconds.
156
        </description>
157
        <availability>1.0</availability>
158
      </attribute>
159
148
      <!-- The entire example section is for usage examples that you want to
160
      <!-- The entire example section is for usage examples that you want to
149
           have added to the HTML doc under "Example" for each tag.  The
161
           have added to the HTML doc under "Example" for each tag.  The
150
           example section is also included with a JSP 1.2 TLD.  The
162
           example section is also included with a JSP 1.2 TLD.  The

Return to bug 18499