Skip to content

Commit

Permalink
Fixes #15. Blocking cache support (missing resource)
Browse files Browse the repository at this point in the history
  • Loading branch information
emacarron committed May 1, 2015
1 parent c4e3bec commit 7f3f6ce
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/main/java/org/mybatis/caches/ehcache/EhBlockingCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2010-2014 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 org.mybatis.caches.ehcache;

import java.util.concurrent.locks.ReadWriteLock;

import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import net.sf.ehcache.constructs.blocking.BlockingCache;

/**
*
* @author Iwao AVE!
*
*/
public class EhBlockingCache extends AbstractEhcacheCache {

public EhBlockingCache(final String id) {
super(id);
if (!CACHE_MANAGER.cacheExists(id)) {
CACHE_MANAGER.addCache(this.id);
Ehcache ehcache = CACHE_MANAGER.getEhcache(this.id);
BlockingCache blockingCache = new BlockingCache(ehcache);
CACHE_MANAGER.replaceCacheWithDecoratedCache(ehcache, blockingCache);
}
}

@Override
public void putObject(Object key, Object value) {
cache.put(new Element(key, value));
}

}

0 comments on commit 7f3f6ce

Please sign in to comment.