2017-12-08 15 views
0

@Cachebleは機能しません。私はSpring MVC Projectでehcacheを使用しています。私のサービスはSpring 4とehcache 2.10バージョンを使用してDAOとして動作しています。@CachebaleはEhcacheとSpring MVCで動作しません

アプリ-ctx.xml以下の実装を参照してください - アプリケーションコンテキストXML

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:p="http://www.springframework.org/schema/p" 
     xmlns:aop="http://www.springframework.org/schema/aop" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:task="http://www.springframework.org/schema/task" 
     xmlns:security="http://www.springframework.org/schema/security" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xmlns:cache="http://www.springframework.org/schema/cache" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security-3.0.3.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd   
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd 
     http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd 
     http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> 

    <cache:annotation-driven /> 
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> 
     <property name="configLocation" value="classpath:ehcache.xml"/> 
     <property name="shared" value="true"/> 
    </bean> 

TelleCallerDashboardService.java

@Service 
public class TelleCallerDashboardService extends BaseNamedParameterJdbcDaoSupport { 

@Cacheable(value = "timeTrackerDashBoardCountCache", key="#league") 
    public void timeTrackerDashBoardCount(final TelleCallerDashboardDTO telleCallerDashboardDTO) { 

} 

の下にサービスクラスを参照してくださいしてください

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="ehcache.xsd" 
    updateCheck="true" 
    monitoring="autodetect" 
    dynamicConfig="true"> 

    <diskStore path="java.io.tmpdir" /> 

    <cache name="timeTrackerDashBoardCountCache" 
     maxEntriesLocalHeap="100" 
     maxEntriesLocalDisk="1000" 
     eternal="false" 
     timeToIdleSeconds="300" 
     timeToLiveSeconds="600" 
     memoryStoreEvictionPolicy="LFU" 
     transactionalMode="off"> 
     <persistence strategy="localTempSwap" /> 
    </cache> 

</ehcache> 

以下ehcache.xmlをご覧ください。

アドバイスをお願いします

+0

方法?また、 '@ Cacheable'は呼び出すメソッドには意味がありません。 –

+0

戻り値の型とキーに入力パラメータの名前、つまりtelleCallerDashboardDTOが必要です。@CacheConfigがありません – Yogi

+0

メソッドtimeTrackerDahshBoardCountは何も返しません。オブジェクトtelleCallerDashboardDTOは呼び出し元のメソッドから渡され、オブジェクトtelleCallerDashboardDTOを使用して値を格納します。データベース。呼び出したメソッドは更新された値を取得します。私は戻り値とkey = telleCallerDashboardDTOでコードをテストします。そして@CacheConfigを追加...ありがとう – giggs

答えて

0

@Cacheableは、キャッシュ可能なメソッド(つまり、同じ引数を使用して結果がキャッシュに格納されるメソッド)を区切るために使用されます。キャッシュ内の値は、メソッドを実際に実行する必要があります。

voidとしてマークされているため、メソッドは何も返しません。 キャッシュには何も入れません。

あなたが@Cacheableや@CachePutを使用する場合は、キャッシュのアノテーションで注釈さ方法で何かを返す必要があります。

@Service 
@CacheConfig(cacheNames = "TelleCallerDashboard") 
public class TelleCallerDashboardService extends BaseNamedParameterJdbcDaoSupport { 

@Cacheable(value = "timeTrackerDashBoardCountCache", key="#telleCallerDashboardDTO") 
    public AnyReturnClass timeTrackerDashBoardCount(final TelleCallerDashboardDTO telleCallerDashboardDTO) { 

     return anyReturnClassObject; 
    } 

} 

さらに読み取りの場合:作業コードの場合

`void`でキャッシュされるべき何
+0

そのまだ機能していない提案してください、 – giggs

関連する問題