Pages enfant
  • 3.18.2 Gestion du cache (utilisation des annotations)

Comparaison des versions

Légende

  • Ces lignes ont été ajoutées. Ce mot a été ajouté.
  • Ces lignes ont été supprimées. Ce mot a été supprimé.
  • La mise en forme a été modifiée.

...

    Déclarer le cacheManager de ehCache dans les properties du module "vue", cache.xmlxml  

   

Bloc de code
<?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:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                            http://www.springframework.org/schema/aop
                            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                            http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
                            http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd">


        <!--
            /properties/cache/cache.xml
            The configuration file for caching features.
            This file should not be modified but by the developers.
            This file is referenced by /properties/applicationContext.xml.
        -->


        <ehcache:annotation-driven/>

        <aop:config proxy-target-class="true" />

        <bean id="cacheManager"
             >
            <description>
                This bean is used to configure EhCache.
            </description>
            <property name="configLocation" value="classpath:/properties/cache/ehcache.xml" />
        </bean>

    </beans>  

    
La configuration du cache se paramètre via le fichier de configuration ehcache.xml.  Ces paramètres sont accessibles depuis la documentation du framework ehCache : http://ehcache.org/documentation/configuration.html

Bloc de code
<ehcache>


        <!--
            /properties/cache/ehcache.xml
            The configuration file for EhCache. This file is referenced
            from /properties/cache/cache.xml.
        -->


        <diskStore path="/tmp/cache"/>


        <cache
            name="org.esupportail.ects.domain.beans.User"
            maxElementsInMemory="1000"
            eternal="false"
            timeToIdleSeconds="30"
            timeToLiveSeconds="60"
            overflowToDisk="true"
            />


        <cache
            name="ehCalculatorController"
            maxElementsInMemory="10000"
            maxElementsOnDisk="10000"
            eternal="false"
            timeToIdleSeconds="1800"
            timeToLiveSeconds="1800"
            overflowToDisk="true"
            />
    </ehcache>

    Attributs du cache

...

    Pour chaque méthode de type get on ajoute l'annotation @Cacheable  avec pour attribut name un identifiant qui servira à identifier le cache associé à la méthode.
    

Bloc de code
public class CalculatorController {

   @Cacheable(cacheName = ehCalculatorController)
   public CalculElp getNewCalculElp(ElpPojo elpPojo) {
       ...
   }

}

...