diaoyudao 发表于 2018-12-25 08:43:56

Spring MVC整合Memcached基于注释的实践使用

  本文并不介绍memcached的安装使用,也不长篇大论哪个缓存框架性能好。而是结合自己实际开发,来谈谈自己的使用。

  一、配置文件application-cache.xml









   
   


               




















   
      
      
      
      
      
            
               
            
      
      
      
      
      
      
            KETAMA_HASH
      
      
      
         
      
      
         
      
   
   
  1、配置文件有一个关键的支持缓存的配置项:,这个配置项缺省使用了一个名字叫 cacheManager 的缓存管理器,我们自定义了一个缓存管理器MemcacheCacheManager,它需要配置一个属性 caches,即此缓存管理器管理的缓存集合。自定义MemcacheSpringCache配置了各个cache的有效时间。
  2、引入第三方spy的客户端MenCacheClientFactoryBean,设置其相关属性。

  

  二、MemcacheCacheManager与MemcacheSpringCache
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.roomy.supply.metadata.cache;
import java.util.Collection;
import org.springframework.cache.Cache;
import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager;
public class MemcacheCacheManager extends AbstractTransactionSupportingCacheManager {
public MemcacheCacheManager() {
}
private Collection
页: [1]
查看完整版本: Spring MVC整合Memcached基于注释的实践使用