Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
switched to lookup tag and using the gemfire template
Browse files Browse the repository at this point in the history
  • Loading branch information
d4v3r committed May 4, 2012
1 parent f23695d commit a9fe15b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
9 changes: 4 additions & 5 deletions vfgf-quickstart/src/main/java/quickstart/DataEviction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import javax.annotation.Resource;

import org.springframework.data.gemfire.GemfireTemplate;
import org.springframework.stereotype.Component;

import com.gemstone.gemfire.cache.Region;

/**
* This example shows cached data eviction. Use eviction to keep a region size
* in check when you can easily get the data again from an outside source. If
Expand All @@ -23,8 +22,8 @@
@Component
public class DataEviction {

@Resource(name = "exampleRegion")
private Region<String, String> exampleRegion;
@Resource(name = "exampleRegionTemplate")
private GemfireTemplate exampleRegionTemplate;

public void run() throws Exception {
System.out
Expand All @@ -43,7 +42,7 @@ public void run() throws Exception {
System.out
.println("the puts and on any destroys done by the eviction controller.");
for (long i = 1; i < 13; i++) {
exampleRegion.put("key" + i, "value" + i);
exampleRegionTemplate.put("key" + i, "value" + i);
Thread.sleep(10);
}
}
Expand Down
24 changes: 5 additions & 19 deletions vfgf-quickstart/src/main/resources/data-eviction-cache-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,12 @@
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd">

<!-- GemFire cache bean -->
<gfe:cache properties-ref="props"/>
<gfe:cache properties-ref="props" cache-xml-location="xml/DataEviction.xml" />

<util:properties id="props" location="cache.properties"/>

<bean id="exampleRegion" class="org.springframework.data.gemfire.RegionFactoryBean"
p:cache-ref="gemfire-cache">
<property name="cacheListeners">
<array>
<bean class="quickstart.SimpleCacheListener" />
</array>
</property>
<property name="attributes">
<bean class="org.springframework.data.gemfire.RegionAttributesFactoryBean">
<property name="evictionAttributes">
<bean class="com.gemstone.gemfire.cache.EvictionAttributes" factory-method="createLRUEntryAttributes">
<constructor-arg value="10" />
<constructor-arg value="LOCAL_DESTROY" />
</bean>
</property>
</bean>
</property>
</bean>
<gfe:lookup-region id="exampleRegion" name="exampleRegion"/>

<bean id="exampleRegionTemplate" class="org.springframework.data.gemfire.GemfireTemplate" p:region-ref="exampleRegion"/>

</beans>
24 changes: 24 additions & 0 deletions vfgf-quickstart/src/main/resources/xml/DataEviction.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!DOCTYPE cache PUBLIC
"-//GemStone Systems, Inc.//GemFire Declarative Caching 6.5//EN"
"http://www.gemstone.com/dtd/cache6_5.dtd">

<!--
| DataEviction.xml
|
| Configures a region to destroy entries when the region reaches
| a certain capacity. Includes a listener to report on the activity.
-->
<cache>
<region name="exampleRegion">
<region-attributes>
<cache-listener>
<class-name>quickstart.SimpleCacheListener</class-name>
</cache-listener>
<eviction-attributes>
<lru-entry-count maximum="10" />
<!-- entry destruction is the default eviction action -->
</eviction-attributes>
</region-attributes>
</region>
</cache>

0 comments on commit a9fe15b

Please sign in to comment.