paulwong

          Spring基于注解的緩存配置--web應用實例

          基于方法級別的緩存:通常如果一個帶有參數的方法執行后會返回一個Object,那可以認為如果參數相同,則返回的結果一樣,這樣就可以為這個方法建立一個緩存Map,參數就是KEY,返回的結果就是VALUE,調用此方法前可以先判斷參數是否和之前的一樣,如果是則從Map中取出結果返回調用者,而無需再進入此方法內執行得到,從而節省了此方法執行時的時間。

          http://hanqunfeng.iteye.com/blog/605123

          經驗證,如果要支持分布式的緩存,用spring-modules-cache不好使,必須轉用com.googlecode.ehcache-spring-annotations

          全套MAVEN的POM:
          <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation
          ="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
              
          <modelVersion>4.0.0</modelVersion>
              
          <groupId>EhCache-Cluster-Tester</groupId>
              
          <artifactId>EhCache-Cluster-Tester</artifactId>
              
          <version>0.0.1-SNAPSHOT</version>
              
          <packaging>war</packaging>
              
          <dependencies>
                  
          <dependency>
                      
          <groupId>net.sf.ehcache</groupId>
                      
          <artifactId>ehcache-jgroupsreplication</artifactId>
                      
          <version>1.4</version>
                  
          </dependency>
                  
          <!-- Spring framework -->
                  
          <dependency>
                      
          <groupId>org.springframework</groupId>
                      
          <artifactId>spring</artifactId>
                      
          <version>${spring.version}</version>
                  
          </dependency>

                  
          <!-- Spring MVC framework -->
                  
          <dependency>
                      
          <groupId>org.springframework</groupId>
                      
          <artifactId>spring-webmvc</artifactId>
                      
          <version>${spring.version}</version>
                  
          </dependency>
                  
          <dependency>
                      
          <groupId>javax.servlet</groupId>
                      
          <artifactId>servlet-api</artifactId>
                      
          <version>2.4</version>
                      
          <scope>provided</scope>
                  
          </dependency>
                  
          <dependency>
                      
          <groupId>org.slf4j</groupId>
                      
          <artifactId>slf4j-jdk14</artifactId>
                      
          <version>1.5.6</version>
                      
          <type>jar</type>
                      
          <scope>compile</scope>
                  
          </dependency>
                  
          <dependency>
                      
          <groupId>log4j</groupId>
                      
          <artifactId>log4j</artifactId>
                      
          <version>1.2.13</version>
                      
          <type>jar</type>
                      
          <scope>compile</scope>
                  
          </dependency>
                  
          <dependency>
                      
          <groupId>cglib</groupId>
                      
          <artifactId>cglib-nodep</artifactId>
                      
          <version>2.2.2</version>
                      
          <type>jar</type>
                      
          <scope>compile</scope>
                  
          </dependency>
                  
          <!-- 
                  <dependency>
                      <groupId>org.springmodules</groupId>
                      <artifactId>spring-modules-cache</artifactId>
                      <version>0.9</version>
                      <type>jar</type>
                      <scope>compile</scope>
                  </dependency>
                  
          -->
                  
          <dependency>
                      
          <groupId>com.googlecode.ehcache-spring-annotations</groupId>
                      
          <artifactId>ehcache-spring-annotations</artifactId>
                      
          <version>1.2.0</version>
                      
          <type>jar</type>
                      
          <scope>compile</scope>
                      
          <exclusions>
                          
          <exclusion>
                              
          <artifactId>spring-aop</artifactId>
                              
          <groupId>org.springframework</groupId>
                          
          </exclusion>
                          
          <exclusion>
                              
          <artifactId>spring-expression</artifactId>
                              
          <groupId>org.springframework</groupId>
                          
          </exclusion>
                      
          </exclusions>
                  
          </dependency>
              
          </dependencies>
              
          <build>
                  
          <finalName>cluster-test</finalName>
                  
          <plugins>
                      
          <plugin>
                          
          <groupId>org.apache.maven.plugins</groupId>
                          
          <artifactId>maven-compiler-plugin</artifactId>
                          
          <configuration>
                              
          <source>1.6</source>
                              
          <target>1.6</target>
                              
          <encoding>UTF-8</encoding>
                          
          </configuration>
                      
          </plugin>
                      
          <plugin>
                          
          <groupId>org.mortbay.jetty</groupId>
                          
          <artifactId>jetty-maven-plugin</artifactId>
                          
          <version>8.0.4.v20111024</version>
                          
          <!-- 
                          <artifactId>maven-jetty-plugin</artifactId>
                          <version>6.1.26</version>
                          
          -->
                          
          <configuration>
                              
          <contextPath>/cluster-test</contextPath>
                              
          <scanIntervalSeconds>3</scanIntervalSeconds>
                              
          <scanTargetPatterns>
                                  
          <scanTargetPattern>
                                      
          <directory>src/main/webapp/WEB-INF</directory>
                                      
          <excludes>
                                          
          <exclude>**/*.jsp</exclude>
                                      
          </excludes>
                                      
          <includes>
                                          
          <include>**/*.properties</include>
                                          
          <include>**/*.xml</include>
                                      
          </includes>
                                  
          </scanTargetPattern>
                              
          </scanTargetPatterns>
                          
          </configuration>
                      
          </plugin>
                  
          </plugins>
              
          </build>
              
          <properties>
                  
          <spring.version>2.5.2</spring.version>
              
          </properties>
          </project>

          posted on 2012-02-16 17:04 paulwong 閱讀(2847) 評論(0)  編輯  收藏 所屬分類: 緩存

          主站蜘蛛池模板: 万源市| 洞头县| 罗江县| 汶上县| 漾濞| 扎赉特旗| 弋阳县| 新源县| 新建县| 礼泉县| 安陆市| 江口县| 霞浦县| 马关县| 光泽县| 友谊县| 阿拉善盟| 宁乡县| 白朗县| 阳朔县| 正安县| 喀什市| 广西| 三台县| 大田县| 同心县| 武威市| 县级市| 台东市| 府谷县| 永顺县| 准格尔旗| 轮台县| 南昌市| 肃南| 抚州市| 汝州市| 潞城市| 永安市| 宜州市| 肇庆市|