You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Paul Spencer <pa...@apache.org> on 2002/01/03 16:12:02 UTC
[T2.2] How to set expiration of RefreshableCachedObject objects during refresh.
I am using the RefreshableCachedObject to store a web page generated by
a remote server. During refresh(), I will re-retrieve the page and
update the cache. In addition to the page, I need to use the lifetime
returned by the server to set the next cache refresh. To do this, I
need to change the value of CachedObject.expires to reflect the new
expiration interval, i.e. from 600000( 10 minutes) to 300000( 5
minutes). The field is private, this not accessible from my class.
The easiest way would be to add setExpire() to RefrshableCachedObject or
CachedObject. I can supply a patch.
Is their a better way?
Paul Spencer
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: [T2.2] How to set expiration of RefreshableCachedObject objects during refresh.
Posted by Paul Spencer <pa...@apache.org>.
This patch, with some additional fixes and enhancements, has been posted
on turbine-dev as "[PATCH] Fixes and enhancements to Caching services"
Paul Spencer
Paul Spencer wrote:
> Below is a patch that allows the Expires field on the CachedObject to be
> set. I also moved the "created" calculation in
> RefreshableCachedObject.refresh() before the r.refresh(). This allows
> the r.refresh() to change Expires (expiration time) without adversely
> affecting when the object becomes stale. I change the calculation for
> "created" to "System.currentTimeMillis()" since the "created +
> getExpires()" will slip up to cacheCheckFrequency Millis per cycle.
>
> Paul Spencer
>
> Index: CachedObject.java
> ===================================================================
> RCS file:
> /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/cache/CachedObject.java,v
>
> retrieving revision 1.1.1.1
> diff -c -r1.1.1.1 CachedObject.java
> *** CachedObject.java 16 Aug 2001 05:08:49 -0000 1.1.1.1
> --- CachedObject.java 4 Jan 2002 05:22:40 -0000
> ***************
> *** 156,161 ****
> --- 156,179 ----
> }
>
> /**
> + * Set the expiration interval for the object.
> + *
> + * @param expires Expiration interval in millis ( 1 second = 1000
> millis)
> + */
> + public void setExpires( long expires ) {
> + if ( expires == DEFAULT ) {
> + this.expires = defaultage;
> + } else {
> + this.expires = expires;
> + }
> + if(expires == FOREVER){
> + setStale(false);
> + } else {
> + setStale( (System.currentTimeMillis() - created) > expires );
> + }
> + }
> +
> + /**
> * Set the stale status for the object.
> *
> * @param stale Whether the object is stale or not.
> Index: RefreshableCachedObject.java
> ===================================================================
> RCS file:
> /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/cache/RefreshableCachedObject.java,v
>
> retrieving revision 1.1.1.1
> diff -c -r1.1.1.1 RefreshableCachedObject.java
> *** RefreshableCachedObject.java 16 Aug 2001 05:08:50 -0000 1.1.1.1
> --- RefreshableCachedObject.java 4 Jan 2002 05:22:45 -0000
> ***************
> *** 147,154 ****
> Refreshable r = (Refreshable)getContents();
> synchronized (this)
> {
> r.refresh();
> - created = created + getExpires();
> }
> }
> }
> --- 147,154 ----
> Refreshable r = (Refreshable)getContents();
> synchronized (this)
> {
> + created = System.currentTimeMillis();
> r.refresh();
> }
> }
> }
>
>
> Paul Spencer wrote:
>
>> I am using the RefreshableCachedObject to store a web page generated
>> by a remote server. During refresh(), I will re-retrieve the page and
>> update the cache. In addition to the page, I need to use the lifetime
>> returned by the server to set the next cache refresh. To do this, I
>> need to change the value of CachedObject.expires to reflect the new
>> expiration interval, i.e. from 600000( 10 minutes) to 300000( 5
>> minutes). The field is private, this not accessible from my class.
>>
>> The easiest way would be to add setExpire() to RefrshableCachedObject
>> or CachedObject. I can supply a patch.
>>
>> Is their a better way?
>>
>> Paul Spencer
>>
>>
>> --
>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>>
>>
>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: [T2.2] How to set expiration of RefreshableCachedObject objects during refresh.
Posted by Paul Spencer <pa...@apache.org>.
Below is a patch that allows the Expires field on the CachedObject to be
set. I also moved the "created" calculation in
RefreshableCachedObject.refresh() before the r.refresh(). This allows
the r.refresh() to change Expires (expiration time) without adversely
affecting when the object becomes stale. I change the calculation for
"created" to "System.currentTimeMillis()" since the "created +
getExpires()" will slip up to cacheCheckFrequency Millis per cycle.
Paul Spencer
Index: CachedObject.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/cache/CachedObject.java,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 CachedObject.java
*** CachedObject.java 16 Aug 2001 05:08:49 -0000 1.1.1.1
--- CachedObject.java 4 Jan 2002 05:22:40 -0000
***************
*** 156,161 ****
--- 156,179 ----
}
/**
+ * Set the expiration interval for the object.
+ *
+ * @param expires Expiration interval in millis ( 1 second = 1000
millis)
+ */
+ public void setExpires( long expires ) {
+ if ( expires == DEFAULT ) {
+ this.expires = defaultage;
+ } else {
+ this.expires = expires;
+ }
+ if(expires == FOREVER){
+ setStale(false);
+ } else {
+ setStale( (System.currentTimeMillis() - created) > expires );
+ }
+ }
+
+ /**
* Set the stale status for the object.
*
* @param stale Whether the object is stale or not.
Index: RefreshableCachedObject.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/cache/RefreshableCachedObject.java,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 RefreshableCachedObject.java
*** RefreshableCachedObject.java 16 Aug 2001 05:08:50 -0000 1.1.1.1
--- RefreshableCachedObject.java 4 Jan 2002 05:22:45 -0000
***************
*** 147,154 ****
Refreshable r = (Refreshable)getContents();
synchronized (this)
{
r.refresh();
- created = created + getExpires();
}
}
}
--- 147,154 ----
Refreshable r = (Refreshable)getContents();
synchronized (this)
{
+ created = System.currentTimeMillis();
r.refresh();
}
}
}
Paul Spencer wrote:
> I am using the RefreshableCachedObject to store a web page generated by
> a remote server. During refresh(), I will re-retrieve the page and
> update the cache. In addition to the page, I need to use the lifetime
> returned by the server to set the next cache refresh. To do this, I
> need to change the value of CachedObject.expires to reflect the new
> expiration interval, i.e. from 600000( 10 minutes) to 300000( 5
> minutes). The field is private, this not accessible from my class.
>
> The easiest way would be to add setExpire() to RefrshableCachedObject or
> CachedObject. I can supply a patch.
>
> Is their a better way?
>
> Paul Spencer
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>