File: cache-service.xml

package info (click to toggle)
turbine 20010419-1
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 17,460 kB
  • ctags: 7,501
  • sloc: java: 41,929; xml: 12,430; sql: 637; sh: 90; makefile: 50
file content (107 lines) | stat: -rw-r--r-- 2,814 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?xml version="1.0"?>

<document>
 <properties>
  <title>Turbine Services</title>
  <author email="jvanzyl@apache.org">Jason van Zyl</author>
 </properties>

<body>

<section name="Cache Service">

<p>
The Global Cache Service provides an object cache that you can call
from anywhere in your application to temporarily store objects. An example
of its use may be to store the names of Countries that you use throughout
your application to populate a look up list. If you normally store the
information about Countries in a database, you can increase the performance
of your application by using the Cache and decreasing the number of hits
against the database.
</p>

</section>

<section name="Configuration">

<source><![CDATA[

# -------------------------------------------------------------------
# 
#  S E R V I C E S
#
# -------------------------------------------------------------------
# Classes for Turbine Services should be defined here.
# Format: services.[name].classname=[implementing class]
#
# To specify properties of a service use the following syntax:
# service.[name].[property]=[value]

services.GlobalCacheService.classname=org.apache.turbine.services.cache.TurbineGlobalCacheService
.
.
.

# -------------------------------------------------------------------
#
#  C A C H E   S E R V I C E
#
# -------------------------------------------------------------------

# Interval at which the cache will be checked. The default is
# 5000ms or 5 seconds.

services.GlobalCacheService.cache.check.frequency = 5000

]]></source>

</section>

<section name="Usage">

<source><![CDATA[

GlobalCacheService 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 = (GlobalCacheService)TurbineServices.getInstance()
        .getService(GlobalCacheService.SERVICE_NAME);

    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 the default time set by the property
<em>cache.check.frequency</em> in the TurbineResources.properties
file. To see an example, look at the file <strong>TestGlobalCache.java</strong>
located in the actions folder.
</p>

</section>

</body>
</document>