Code Monkey home page Code Monkey logo

spring_mem_plugin's Introduction

###spring_mem_plugin

顾名思义是基于spring和memcached的一个插件,该插件目前实现了memcached的查询缓存,利用java的annotation方式和spring的AOP切面编程使得我们在业务层获得缓存数据非常的方便

##开始使用 首先你必须实现CacheSupport接口,我正好提供了一个memcachedDefault类给你

package org.xie.framework.memcached.spring;

import org.xie.memcached.client.MemcachedCache;

public class MemcachedDefault implements CacheSupport {
	private MemcachedCache cached;
	public void setCached(MemcachedCache cached) {
		this.cached = cached;
	}

	@Override
	public boolean addCache(String key, Object value) {
		return cached.getCache().add(key, value);
	}

	@Override
	public boolean addCache(String key, Object value, long cacheTime) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteCache(String key) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Object getCache(String key) {
		return 	cached.get(key);
	
	}

	@Override
	public boolean replaceCache(String key, Object value) {
		// TODO Auto-generated method stub
		return false;
	}

}

当然这只是一个简单的例子,你可以按照你自己要实现的memcached客户端方式去实现它 然后你需要配置applicationContext.xml.像下面这样

	
	<bean id="memDefault" class="org.xie.framework.memcached.spring.MemcachedDefault">
		<property name="cached" ref="memClient"></property><!-- 注入自己的客户端 -->
	</bean>
	<bean id="cacheAop" class="org.xie.framework.memcached.spring.GetCacheAop">
	<property name="cacheSupport" ref="memDefault"></property><!-- 注入实现 -->
	</bean>
	<aop:aspectj-autoproxy proxy-target-class="true"/> <!-- cglib代理必须要开启-->
	<aop:config>	
		<aop:aspect id="myAspect" ref="cacheAop">
		<!-- 配置切点。和环绕通知。method=“ProxyInvoke” -->
			<aop:pointcut id="businessService" expression="execution(* org.xie.service.*.*(..))" />
			<aop:around pointcut-ref="businessService" method="ProxyInvoke" />
		</aop:aspect>
	
	</aop:config>

###annotation使用

@GetCacheVaule(key="id")//表示要缓存id
	public Object testaop(String id) {
		
		return userDao.getUsers();
	}

这个的意思是,传入的id是要缓存的键值,如果缓存中有则拿出来,没有则从数据库中拿,注意返回值要这样写哦! 目前只有这一个,其实已经差不多足够,以后有时间再写吧

spring_mem_plugin's People

Contributors

yaccc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.