OSCache - Spring

Configuring a GeneralCacheAdministrator
A GeneralCacheAdministrator instance that picks up configuration from an oscache.properties file can be configured within Spring using the following code:
<bean id="cacheAdministrator" class="com.opensymphony.oscache.general.GeneralCacheAdministrator" destroy-method="destroy"/>
Notice that a destory-method is configured to ensure that the GeneralCacheAdministrator is closed down gracefully.
If you'd prefer to keep all your configuration inside the Spring configuration, you can omit the oscache.properties file and pass in any properties you want to the GeneralCacheAdministrator constructor like so:
<bean id="cacheAdministrator" class="com.opensymphony.oscache.general.GeneralCacheAdministrator" destroy-method="destroy">
    <constructor-arg index="0">
        <props>
            <prop key="cache.memory">true</prop>
        </props>
    </constructor-arg>
</bean>
Configuring a Cache
You can configure a Cache instance directly using the following snippet of code:
<bean id="cache" class="com.opensymphony.oscache.base.Cache">
    <constructor-arg index="0">
        <value>true</value> <!-- useMemoryCaching -->
    <constructor-arg>
    <constructor-arg index="1">
        <value>true</value> <!-- unlimitedDiskCache -->
    <constructor-arg>
    <constructor-arg index="2">
        <value>true</value> <!-- overflowPersistence -->
    <constructor-arg>
</bean>
Alternatively, you can pick up the Cache from the GeneralCacheAdministrator like so:
<bean id="cacheAdministrator" class="com.opensymphony.oscache.general.GeneralCacheAdministrator" destroy-method="destroy"/>

<bean id="cache" factory-bean="cacheAdministrator" factory-method="getCache"/>

你可能感兴趣的:(spring,bean,cache,UP)