-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
191 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apply plugin: 'kotlin' | ||
|
||
def libs = rootProject.ext.libraries | ||
|
||
dependencies { | ||
implementation "io.vertx:vertx-redis-client:${libs.vertx}" | ||
implementation "io.vertx:vertx-lang-kotlin-coroutines:${libs.vertx}" | ||
implementation project(':festival-context') | ||
} | ||
|
||
compileKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
} | ||
compileTestKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
} |
2 changes: 1 addition & 1 deletion
2
...n/bdqfork/web/cache/annotation/Cache.java → ...va/cn/bdqfork/cache/annotation/Cache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cn.bdqfork.web.cache.annotation; | ||
package cn.bdqfork.cache.annotation; | ||
|
||
import java.lang.annotation.*; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...n/bdqfork/web/cache/annotation/Evict.java → ...va/cn/bdqfork/cache/annotation/Evict.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cn.bdqfork.web.cache.annotation; | ||
package cn.bdqfork.cache.annotation; | ||
|
||
import java.lang.annotation.*; | ||
|
||
|
4 changes: 3 additions & 1 deletion
4
...fork/kotlin/web/constant/CacheProperty.kt → ...n/bdqfork/cache/constant/CacheProperty.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package cn.bdqfork.kotlin.web.constant | ||
package cn.bdqfork.cache.constant | ||
|
||
/** | ||
* @author bdq | ||
* @since 2020/2/17 | ||
*/ | ||
object CacheProperty { | ||
const val DEFAULT_EXPIRE_TIME = 60 | ||
|
||
const val CACHE_ENABLE = "cache.enable" | ||
const val CACHE_TYPE = "cache.type" | ||
} |
42 changes: 42 additions & 0 deletions
42
festival-cache/src/main/java/cn/bdqfork/cache/processor/CacheSupportProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cn.bdqfork.cache.processor; | ||
|
||
import cn.bdqfork.cache.provider.CacheProvider; | ||
import cn.bdqfork.cache.proxy.CacheInvocationHandler; | ||
import cn.bdqfork.context.aware.BeanFactoryAware; | ||
import cn.bdqfork.context.aware.ClassLoaderAware; | ||
import cn.bdqfork.core.exception.BeansException; | ||
import cn.bdqfork.core.factory.BeanFactory; | ||
import cn.bdqfork.core.factory.processor.BeanPostProcessor; | ||
import cn.bdqfork.core.proxy.javassist.Proxy; | ||
import cn.bdqfork.core.util.AopUtils; | ||
|
||
/** | ||
* @author bdq | ||
* @since 2020/2/21 | ||
*/ | ||
public class CacheSupportProcessor implements BeanPostProcessor, BeanFactoryAware, ClassLoaderAware { | ||
private ClassLoader classLoader; | ||
private BeanFactory beanFactory; | ||
|
||
@Override | ||
public Object postProcessBeforeInitializtion(String beanName, Object bean) throws BeansException { | ||
return bean; | ||
} | ||
|
||
@Override | ||
public Object postProcessAfterInitializtion(String beanName, Object bean) throws BeansException { | ||
Class<?> targetClass = AopUtils.getTargetClass(bean); | ||
CacheProvider cacheProvider = beanFactory.getBean(CacheProvider.class); | ||
return Proxy.newProxyInstance(classLoader, targetClass.getInterfaces(), new CacheInvocationHandler(bean, cacheProvider)); | ||
} | ||
|
||
@Override | ||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { | ||
this.beanFactory = beanFactory; | ||
} | ||
|
||
@Override | ||
public void setClassLoader(ClassLoader classLoader) throws BeansException { | ||
this.classLoader = classLoader; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
festival-cache/src/main/java/cn/bdqfork/cache/provider/AbstractCacheProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cn.bdqfork.cache.provider; | ||
|
||
import cn.bdqfork.cache.constant.CacheProperty; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* @author bdq | ||
* @since 2020/2/21 | ||
*/ | ||
public abstract class AbstractCacheProvider implements CacheProvider { | ||
@Override | ||
public void put(String key, Serializable value) { | ||
put(key, value, CacheProperty.DEFAULT_EXPIRE_TIME); | ||
} | ||
|
||
@Override | ||
public Object update(String key, Serializable value) { | ||
return update(key, value, CacheProperty.DEFAULT_EXPIRE_TIME); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
festival-cache/src/main/java/cn/bdqfork/cache/provider/RedisCacheProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cn.bdqfork.cache.provider; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* @author bdq | ||
* @since 2020/2/21 | ||
*/ | ||
public class RedisCacheProvider extends AbstractCacheProvider { | ||
@Override | ||
public void put(String key, Serializable value, long expireTime) { | ||
|
||
} | ||
|
||
@Override | ||
public void remove(String key) { | ||
|
||
} | ||
|
||
@Override | ||
public Object update(String key, Serializable value, long expireTime) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object get(String key) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean containKey(String key) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
|
||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
festival-cache/src/main/java/cn/bdqfork/cache/proxy/CacheInvocationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cn.bdqfork.cache.proxy; | ||
|
||
import cn.bdqfork.cache.provider.CacheProvider; | ||
import cn.bdqfork.cache.annotation.Cache; | ||
import cn.bdqfork.cache.annotation.Evict; | ||
import cn.bdqfork.core.util.AnnotationUtils; | ||
|
||
import java.io.Serializable; | ||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* @author bdq | ||
* @since 2020/2/21 | ||
*/ | ||
public class CacheInvocationHandler implements InvocationHandler { | ||
private Object target; | ||
private CacheProvider cacheProvider; | ||
|
||
public CacheInvocationHandler(Object target, CacheProvider cacheProvider) { | ||
this.target = target; | ||
this.cacheProvider = cacheProvider; | ||
} | ||
|
||
@Override | ||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
|
||
if (AnnotationUtils.isAnnotationPresent(method, Cache.class)) { | ||
Cache cache = AnnotationUtils.getMergedAnnotation(method, Cache.class); | ||
String cacheKey = cache.value(); | ||
if (cacheProvider.containKey(cacheKey)) { | ||
return cacheProvider.get(cacheKey); | ||
} | ||
Object result = method.invoke(target, args); | ||
cacheProvider.put(cacheKey, (Serializable) result, cache.expireTime()); | ||
return result; | ||
} | ||
|
||
if (AnnotationUtils.isAnnotationPresent(method, Evict.class)) { | ||
Object result = method.invoke(target, args); | ||
Evict evict = AnnotationUtils.getMergedAnnotation(method, Evict.class); | ||
cacheProvider.remove(evict.value()); | ||
return result; | ||
} | ||
|
||
return method.invoke(target, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
festival-kotlin-web/src/main/kotlin/cn/bdqfork/kotlin/web/cache/CacheProvider.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
festival-web/src/main/java/cn/bdqfork/web/constant/CacheProperty.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters