| <?xml version="1.0"?> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| --> |
| |
| <document> |
| |
| <properties> |
| <title>Template Component</title> |
| <author email="epugh@opensourceconnections.com">Eric Pugh</author> |
| </properties> |
| |
| <body> |
| |
| <section name="Overview"> |
| <p> |
| This Service functions as a Template component. |
| </p> |
| |
| <p> |
| It is written |
| for use in Turbine but it can be used in any container compatible |
| with Avalon's ECM container. |
| </p> |
| </section> |
| |
| <section name="Configuration"> |
| |
| <p> |
| First, here is the role configuration. |
| </p> |
| |
| <source> |
| <![CDATA[ |
| <role |
| name="org.apache.fulcrum.bsf.BSFService" |
| shorthand="cache" |
| default-class="org.apache.fulcrum.bsf.TurbineBSFService"/> |
| ]]> |
| </source> |
| |
| <p> |
| And here is the configuration: |
| </p> |
| <source> |
| |
| <![CDATA[ |
| <cache cacheInitialSize="20" cacheCheckFrequency="5"/> |
| ]]> |
| </source> |
| |
| </section> |
| |
| <section name="Usage"> |
| |
| <source><![CDATA[ |
| |
| TemplateService gs = null; |
| try |
| { |
| /* |
| * Look for the item in the cache. |
| * If it doesn't exist or the item is stale, |
| * the cache will throw an exception. |
| */ |
| gs = (TemplateService)avalonComponentService.lookup(TemplateService.ROLE) |
| |
| CachedObject obj = gs.getObject("cached_object"); |
| |
| data.setMessage( data.getScreen() + " Got " + |
| obj.getContents().toString() + " from global cache!" ); |
| } |
| catch(ObjectExpiredException gone) |
| { |
| /* |
| * Add the item to the cache. |
| */ |
| gs.addObject("cached_object", |
| new CachedObject("in_the_cache",5000)); |
| |
| data.setMessage( data.getScreen() + |
| " Refreshed/or added new item to" + |
| " the cache! Expires in 5 seconds" ); |
| } |
| |
| ]]></source> |
| |
| <p> |
| You can also place an expiration time on your objects so the Service will |
| automatically remove them when they expire. If you don't specify an expiration |
| time, the Service uses 5 seconds. To see an example, look at the |
| test case <a href="xref-test/org/apache/fulcrum/cache/CacheTest.html">CacheTest</a> |
| </p> |
| |
| </section> |
| |
| </body> |
| </document> |