https://github.com/m3dev/method-cache-interceptor
Method Result Cache Interceptor for Java Applications
https://github.com/m3dev/method-cache-interceptor
Last synced: 5 months ago
JSON representation
Method Result Cache Interceptor for Java Applications
- Host: GitHub
- URL: https://github.com/m3dev/method-cache-interceptor
- Owner: m3dev
- Archived: true
- Created: 2012-09-10T05:24:41.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2013-03-16T05:08:21.000Z (over 13 years ago)
- Last Synced: 2025-12-16T13:30:30.297Z (6 months ago)
- Size: 136 KB
- Stars: 3
- Watchers: 65
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Method Cache Interceptor
## Getting Started
### Maven
```xml
com.m3
method-cache-interceptor
1.0.1
```
## Usage with Memcached
### memcached-client-facade
MemcachedCacheResultInterceptor uses memcached-client-facade internally.
Also take a look at memcached-client-facade's document:
https://github.com/m3dev/memcached-client-facade
### Setup for Spring Framework
"applicationContext.xml" as follows:
```xml
```
### Setup by inheritence
It's also possible to inject the configuration to interceptor by inheritence.
```java
import com.m3.methodcache.MemcachedCacheResultInterceptor;
import com.m3.memcached.facade.Configuration;
public class MyMemcachedInterceptor extends MemcachedCacheResultInterceptor {
@Override
public Configuration getConfiguration() {
Configuration config = new Configuration();
config.setNamespace("....");
...
return config;
}
}
```
### Using AOP
The value will be cached for the duration of 10 seconds.
```java
package service;
import com.m3.methodcache.annotation.CacheResult;
public class DateService {
@CacheResult(secondsToExpire = 10)
public String getCurrentAsString(String prefix) {
return prefix + new java.util.Date().toString();
}
}
```
### The rule of generated cache key
```
"(namespace)::(Method#toGenericString() and replace "\\s+" to "_")::(args separated by comma)"
```
For example:
```java
String result = new DateService().getCurrentAsString("PREFIX");
```
And thn, the returned value will be cached as "com.example::public_void_service.DateService.getCurrentAsString(String)::PREFIX" on memcached.
### Example
See also:
https://github.com/m3dev/method-cache-interceptor/tree/master/sample
## License
```
Copyright 2011 - 2012 M3, Inc.
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.
```