当前位置: 首页>>代码示例>>Java>>正文


Java UtilCache.putIfAbsentAndGet方法代码示例

本文整理汇总了Java中org.ofbiz.base.util.cache.UtilCache.putIfAbsentAndGet方法的典型用法代码示例。如果您正苦于以下问题:Java UtilCache.putIfAbsentAndGet方法的具体用法?Java UtilCache.putIfAbsentAndGet怎么用?Java UtilCache.putIfAbsentAndGet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ofbiz.base.util.cache.UtilCache的用法示例。


在下文中一共展示了UtilCache.putIfAbsentAndGet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTemplate

import org.ofbiz.base.util.cache.UtilCache; //导入方法依赖的package包/类
/**
 * Gets a Template instance from the template cache. If the Template instance isn't
 * found in the cache, then one will be created.
 * <p>
 * SCIPIO: 2017-02-21: May now pass cache null to bypass caching.
 */
public static Template getTemplate(String templateLocation, UtilCache<String, Template> cache, Configuration config) throws TemplateException, IOException {
    Template template = (cache != null) ? cache.get(templateLocation) : null;
    if (template == null) {
        // only make the reader if we need it, and then close it right after!
        Reader templateReader = makeReader(templateLocation);
        try {
            template = new Template(templateLocation, templateReader, config);
        } finally { // SCIPIO: added finally
            templateReader.close();
        }
        if (cache != null) {
            template = cache.putIfAbsentAndGet(templateLocation, template);
        }
    }
    return template;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:23,代码来源:FreeMarkerWorker.java

示例2: getTemplateFromString

import org.ofbiz.base.util.cache.UtilCache; //导入方法依赖的package包/类
/**
 * SCIPIO: Gets template from string out of custom cache (new).
 * 2017-02-21: May now pass cache null to bypass caching.
 */
public static Template getTemplateFromString(String templateString, String templateKey, String templateName, UtilCache<String, Template> cache, Configuration config) throws TemplateException, IOException {
    Template template = (cache != null) ? cache.get(templateKey) : null;
    if (template == null) {
        Reader templateReader = new StringReader(templateString);
        try {
            template = new Template(templateName, templateReader, config);
        } finally {
            templateReader.close();
        }
        if (cache != null) {
            template = cache.putIfAbsentAndGet(templateKey, template);
        }
    }
    return template;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:20,代码来源:FreeMarkerWorker.java

示例3: testPutIfAbsentAndGet

import org.ofbiz.base.util.cache.UtilCache; //导入方法依赖的package包/类
public void testPutIfAbsentAndGet() throws Exception {
    UtilCache<String, String> cache = createUtilCache(5, 5, 2000, false, false);
    Listener<String, String> gotListener = createListener(cache);
    Listener<String, String> wantedListener = new Listener<String, String>();
    wantedListener.noteKeyAddition(cache, "key", "value");
    wantedListener.noteKeyAddition(cache, "anotherKey", "anotherValue");
    assertNull("no-get", cache.get("key"));
    assertEquals("putIfAbsentAndGet", "value", cache.putIfAbsentAndGet("key", "value"));
    assertHasSingleKey(cache, "key", "value");
    assertEquals("putIfAbsentAndGet", "value", cache.putIfAbsentAndGet("key", "newValue"));
    assertHasSingleKey(cache, "key", "value");
    String anotherValueAddedToCache = new String("anotherValue");
    String anotherValueNotAddedToCache = new String("anotherValue");
    assertEquals(anotherValueAddedToCache, anotherValueNotAddedToCache);
    assertNotSame(anotherValueAddedToCache, anotherValueNotAddedToCache);
    String cachedValue = cache.putIfAbsentAndGet("anotherKey", anotherValueAddedToCache);
    assertSame(cachedValue, anotherValueAddedToCache);
    cachedValue = cache.putIfAbsentAndGet("anotherKey", anotherValueNotAddedToCache);
    assertNotSame(cachedValue, anotherValueNotAddedToCache);
    assertSame(cachedValue, anotherValueAddedToCache);
    cache.removeListener(gotListener);
    assertEquals("listener", wantedListener, gotListener);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:24,代码来源:UtilCacheTests.java

示例4: getTemplate

import org.ofbiz.base.util.cache.UtilCache; //导入方法依赖的package包/类
public static Template getTemplate(String templateLocation, UtilCache<String, Template> cache, Configuration config) throws TemplateException, IOException {
    Template template = cache.get(templateLocation);
    if (template == null) {
        // only make the reader if we need it, and then close it right after!
        Reader templateReader = makeReader(templateLocation);
        template = new Template(templateLocation, templateReader, config);
        templateReader.close();
        template = cache.putIfAbsentAndGet(templateLocation, template);
    }
    return template;
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:12,代码来源:FreeMarkerWorker.java


注:本文中的org.ofbiz.base.util.cache.UtilCache.putIfAbsentAndGet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。