An open API service indexing awesome lists of open source software.

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

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.
```