2015-08-06 31 views
9

Kurulumu:Oynatma çerçevesinde özel ehcaches nasıl yapılandırılır?

java (önbellek boyutları , ömürleri vb.) ben uygulama içinde yapılandırın:

play.cache.bindCaches = ["mycache1-cache","mycache2-cache"] 
:Sonra onları yapılandırmak, ben sadece defaultCache tutmak, ama en kısa sürede özel önbellek eklemek gibi oyun ile atar zaman çalışır zamanki ehcache.xml dosyasını

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd" updateCheck="false"> 

    <defaultCache 
     maxBytesLocalHeap="256000000" 
     eternal="false" 
     timeToIdleSeconds="120" 
     timeToLiveSeconds="120" 
     overflowToDisk="false" 
     maxElementsOnDisk="10000" 
     diskPersistent="false" 
     diskExpiryThreadIntervalSeconds="120" 
     memoryStoreEvictionPolicy="LRU" 
     /> 

    <cache name="mycache1-cache" 
      maxBytesLocalHeap="256000000" 
      eternal="false" 
      timeToIdleSeconds="86400" 
      timeToLiveSeconds="86400" 
      overflowToDisk="true" 
      maxElementsOnDisk="1000000" 
      diskPersistent="true" 
      diskExpiryThreadIntervalSeconds="1200" 
      memoryStoreEvictionPolicy="LRU" 
      /> 

</ehcache> 

yarattı

ProvisionException: hükme edemeyen aşağıdaki hataları bakın: özel sağlayıcısı 1) hata, net.sf.ehcache.ObjectExistsException: Önbellek mycache1-önbellek zaten Ancak

var sadece önbelleği ehcache.xml içinde tanımladığım halde application.conf dosyasında tanımıyorsam, oyun bunu bilmiyor ve atar.

+0

Tam stacktrace bu mu? – dan

+0

'oyun oynamayı bilmiyor ve atar -> hangi istisna oyun tarafından atılır? –

+0

Bununla herhangi bir şansın var mı? – metasim

cevap

0

Ayrıca bir ay önce aynı sorunla karşı karşıya kaldım ve benim için işe yarayan internet ve çözüm arayışına girdim. Aynı şeyi yapmaya da çalışabilirsiniz.

/** Bind named caches using configuration in ehcache.xml. Define a named cache in ehcache.xml and Ehcache will automatically instantiate the cache at runtime. However,this cache is unknown to the Play cache plugin and is not accessible using {@code @NamedCache}. You must bind a reference to the named cache using {@link CacheModule#bindCustomCache(String)}. Do not add the named cache to {@code play.cache.bindCaches} in configuration. Caches bound in this manner are programmatically added by the Play cache plugin at runtime. The cache plugin will always copy settings from the default cache, limiting the usefulness of named caches. **/ 

public class CacheModule extends AbstractModule { 

@Override 
protected void configure() { 
    bindCustomCache("tenants"); 
    bindCustomCache("user-agent"); 
    bindCustomCache("geo-ip"); 
    bindCustomCache("full-contact"); 
} 

/** 
* Bind a named cache that is defined in ehcache.xml. 
* 
* @param name The name of the cache. 
*/ 
private void bindCustomCache(String name) { 
    bind(CacheApi.class) 
      .annotatedWith(new NamedCacheImpl(name)) 
      .toProvider(new Provider<CacheApi>() { 

       @Inject 
       CacheManager cacheManager; 

       @Override 
       public CacheApi get() { 
        Cache cache = cacheManager.getCache(name); 
        if (cache == null) { 
         throw new RuntimeException("Cache named '" + name + "' must be defined in ehcache.xml"); 
        } 
        return new DefaultCacheApi(new EhCacheApi(cache)); 
       } 

      }) 
      .asEagerSingleton(); 
    } 
} 

Ben ehcache.xml benim adlandırılmış önbelleklerini oluşturmak ve sadece yapılandırmak yöntemine tek satır bindCustomCache() eklemeniz gerekir.

İlgili konular