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


Java Cache.get方法代码示例

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


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

示例1: main

import org.ehcache.Cache; //导入方法依赖的package包/类
public static void main(String[] args) {
  LOGGER.info("Creating cache manager via XML resource");
  Configuration xmlConfig = new XmlConfiguration(BasicXML.class.getResource("/ehcache.xml"));
  try (CacheManager cacheManager = newCacheManager(xmlConfig)) {
    cacheManager.init();

    Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class);

    LOGGER.info("Putting to cache");
    basicCache.put(1L, "da one!");
    String value = basicCache.get(1L);
    LOGGER.info("Retrieved '{}'", value);

    LOGGER.info("Closing cache manager");
  }

  LOGGER.info("Exiting");
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:19,代码来源:BasicXML.java

示例2: doGetAuthenticationInfo

import org.ehcache.Cache; //导入方法依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) throws AuthenticationException {
    String token = (String) auth.getCredentials();
    Cache<String, String> authCache = CacheController.getAuthCache();
    if (! authCache.containsKey(token)) {
        // get user info from database
        int uid = JWTUtil.getUid(token);
        UserEntity userEntity = userService.getUserByUid(uid);
        authCache.put(token, String.valueOf(userEntity.getPassword()));
    }

    String secret = authCache.get(token);
    if (!JWTUtil.decode(token, secret)) {
        throw new AuthenticationException("Token invalid");
    }

    return new SimpleAuthenticationInfo(token, token, "jwt_realm");
}
 
开发者ID:Eagle-OJ,项目名称:eagle-oj-api,代码行数:19,代码来源:Realm.java

示例3: testTem

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testTem() {
    CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
    .withCache("preConfigured",
       CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)))
    .build();

    cacheManager.init();

    Cache<Long, String> preConfigured =
            cacheManager.getCache("preConfigured", Long.class, String.class);

    Cache<Long, String> myCache = cacheManager.createCache("myCache",
            CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)));

    myCache.put(1L, "da one!");
    myCache.putIfAbsent(0L, "ee");
    String value = myCache.get(1L);

    System.out.println("Value is " + value);
    cacheManager.removeCache("preConfigured");
    cacheManager.close();
}
 
开发者ID:compasses,项目名称:elastic-rabbitmq,代码行数:24,代码来源:TestEhcache.java

示例4: main

import org.ehcache.Cache; //导入方法依赖的package包/类
public static void main(String[] args) {
  LOGGER.info("Creating cache manager programmatically");
  try (CacheManager cacheManager = newCacheManagerBuilder()
    .withCache("basicCache",
      newCacheConfigurationBuilder(Long.class, String.class, heap(100).offheap(1, MB)))
    .build(true)) {
    Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class);

    LOGGER.info("Putting to cache");
    basicCache.put(1L, "da one!");
    String value = basicCache.get(1L);
    LOGGER.info("Retrieved '{}'", value);

    LOGGER.info("Closing cache manager");
  }

  LOGGER.info("Exiting");
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:19,代码来源:BasicProgrammatic.java

示例5: main

import org.ehcache.Cache; //导入方法依赖的package包/类
public static void main(String[] args) {
  LOGGER.info("Creating clustered cache manager from XML");
  final URL myUrl = ClusteredXML.class.getResource("/ehcache.xml");
  Configuration xmlConfig = new XmlConfiguration(myUrl);
  try (CacheManager cacheManager = newCacheManager(xmlConfig)) {
    cacheManager.init();
    
    Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class);
    
    LOGGER.info("Getting from cache");
    String value = basicCache.get(1L);
    LOGGER.info("Retrieved '{}'", value);

    LOGGER.info("Closing cache manager");
  }

  LOGGER.info("Exiting");
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:19,代码来源:ClusteredXML.java

示例6: testOnHeapPutGet

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testOnHeapPutGet() {

  Cache<Long, String> cache = cacheManager.createCache("onHeap", newCacheConfigurationBuilder(Long.class, String.class, heap(10))
              .add(new DefaultCopierConfiguration<>(SerializingCopier.<Long>asCopierClass(), DefaultCopierConfiguration.Type.KEY))
              .add(new DefaultCopierConfiguration<>(SerializingCopier.<String>asCopierClass(), DefaultCopierConfiguration.Type.VALUE))
              .build());

  cache.put(42L, "TheAnswer!");
  assertCounters(2, 2, 0, 1, 0, 0);
  printSerializationCounters("Put OnHeap (create)");
  cache.get(42L);
  assertCounters(0, 0, 0, 0, 1, 0);
  printSerializationCounters("Get OnHeap");

  cache.put(42L, "Wrong ...");
  assertCounters(2, 2, 0, 1, 0, 0);
  printSerializationCounters("Put OnHeap (update)");
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:20,代码来源:SerializerCountingTest.java

示例7: testGetNoExpirationPropagatedToHigherTiers

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testGetNoExpirationPropagatedToHigherTiers() throws CachePersistenceException {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = cacheManagerBuilder(ExpiryPolicyBuilder.noExpiration());

  try(PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true)) {

    Map<String, TierStatistics> tierStatistics = statisticsService.getCacheStatistics(CLUSTERED_CACHE).getTierStatistics();
    TierStatistics onheap = tierStatistics.get("OnHeap");
    TierStatistics offheap = tierStatistics.get("OffHeap");

    Cache<Long, String> cache = cacheManager.getCache(CLUSTERED_CACHE, Long.class, String.class);
    for (long i = 0; i < 30; i++) {
      cache.put(i, "value"); // store on the cluster
      cache.get(i); // push it up on heap and offheap tier
    }

    assertThat(onheap.getMappings()).isEqualTo(10);
    assertThat(offheap.getMappings()).isEqualTo(20);
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:ClusteredCacheExpirationTest.java

示例8: testCopyValueOnRead

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testCopyValueOnRead() throws Exception {
  CacheConfiguration<Long, Person> cacheConfiguration = baseConfig
      .add(new DefaultCopierConfiguration<>(PersonOnReadCopier.class, DefaultCopierConfiguration.Type.VALUE))
      .build();

  Cache<Long, Person> cache = cacheManager.createCache("cache", cacheConfiguration);

  Person original = new Person("Bar", 24);
  cache.put(1l, original);

  Person retrieved = cache.get(1l);
  assertNotSame(original, retrieved);
  assertThat(retrieved.name, equalTo("Bar"));
  assertThat(retrieved.age, equalTo(24));

  original.age = 56;
  retrieved = cache.get(1l);
  assertThat(retrieved.age, equalTo(56));

  assertNotSame(cache.get(1l), cache.get(1l));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:CacheCopierTest.java

示例9: testCopyValueOnWrite

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testCopyValueOnWrite() throws Exception {
  CacheConfiguration<Long, Person> cacheConfiguration = baseConfig
      .add(new DefaultCopierConfiguration<>(PersonOnWriteCopier.class, DefaultCopierConfiguration.Type.VALUE))
      .build();

  Cache<Long, Person> cache = cacheManager.createCache("cache", cacheConfiguration);

  Person original = new Person("Bar", 24);
  cache.put(1l, original);

  Person retrieved = cache.get(1l);
  assertNotSame(original, retrieved);
  assertThat(retrieved.name, equalTo("Bar"));
  assertThat(retrieved.age, equalTo(24));

  original.age = 56;
  retrieved = cache.get(1l);
  assertThat(retrieved.age, equalTo(24));

  assertSame(cache.get(1l), cache.get(1l));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:CacheCopierTest.java

示例10: testDiskOffHeapOnHeapCopyPutGet

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testDiskOffHeapOnHeapCopyPutGet() {
  Cache<Long, String> cache = cacheManager.createCache("offHeap", newCacheConfigurationBuilder(Long.class, String.class,
                newResourcePoolsBuilder().heap(2, EntryUnit.ENTRIES).offheap(10, MemoryUnit.MB).disk(100, MemoryUnit.MB))
          .add(new DefaultCopierConfiguration<>(SerializingCopier.<Long>asCopierClass(), DefaultCopierConfiguration.Type.KEY))
          .add(new DefaultCopierConfiguration<>(SerializingCopier.<String>asCopierClass(), DefaultCopierConfiguration.Type.VALUE))
          .build()
  );


  cache.put(42L, "TheAnswer");
  assertCounters(3, 2, 0, 1, 0, 0);
  printSerializationCounters("Put DiskOffHeapOnHeapCopy");
  cache.get(42L);
  assertCounters(1, 1, 1, 0, 2, 0);
  printSerializationCounters("Get DiskOffHeapOnHeapCopy fault");
  cache.get(42L);
  assertCounters(0, 0, 0, 0, 1, 0);
  printSerializationCounters("Get DiskOffHeapOnHeapCopy faulted");

  cache.put(42L, "Wrong ...");
  assertCounters(3, 2, 2, 1, 0, 0);
  printSerializationCounters("Put DiskOffHeapOnHeapCopy (update faulted)");
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:SerializerCountingTest.java

示例11: testSerializingCopier

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testSerializingCopier() throws Exception {
  CacheConfiguration<Long, Person> cacheConfiguration = baseConfig
      .add(new DefaultCopierConfiguration<>(SerializingCopier.<Person>asCopierClass(), DefaultCopierConfiguration.Type.VALUE))
      .add(new DefaultSerializerConfiguration<>(PersonSerializer.class, DefaultSerializerConfiguration.Type.VALUE))
      .build();

  Cache<Long, Person> cache = cacheManager.createCache("cache", cacheConfiguration);

  Person original = new Person("Bar", 24);
  cache.put(1l, original);

  Person retrieved = cache.get(1l);
  assertNotSame(original, retrieved);
  assertThat(retrieved.name, equalTo("Bar"));
  assertThat(retrieved.age, equalTo(24));

  original.age = 56;
  retrieved = cache.get(1l);
  assertThat(retrieved.age, equalTo(24));

  assertNotSame(cache.get(1l), cache.get(1l));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:24,代码来源:CacheCopierTest.java

示例12: testReadWriteCopier

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testReadWriteCopier() throws Exception {
  CacheConfiguration<Long, Person> cacheConfiguration = baseConfig
      .add(new DefaultCopierConfiguration<>(PersonCopier.class, DefaultCopierConfiguration.Type.VALUE))
      .build();

  Cache<Long, Person> cache = cacheManager.createCache("cache", cacheConfiguration);

  Person original = new Person("Bar", 24);
  cache.put(1l, original);

  Person retrieved = cache.get(1l);
  assertNotSame(original, retrieved);
  assertThat(retrieved.name, equalTo("Bar"));
  assertThat(retrieved.age, equalTo(24));

  original.age = 56;
  retrieved = cache.get(1l);
  assertThat(retrieved.age, equalTo(24));

  assertNotSame(cache.get(1l), cache.get(1l));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:CacheCopierTest.java

示例13: cachemanagerExample

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void cachemanagerExample() {
  // tag::cachemanagerExample[]
  CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() // <1>
      .withCache("preConfigured",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10))) // <2>
      .build(); // <3>
  cacheManager.init(); // <4>

  Cache<Long, String> preConfigured =
      cacheManager.getCache("preConfigured", Long.class, String.class); // <5>

  Cache<Long, String> myCache = cacheManager.createCache("myCache", // <6>
      CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)));

  myCache.put(1L, "da one!"); // <7>
  String value = myCache.get(1L); // <8>

  cacheManager.removeCache("preConfigured"); // <9>

  cacheManager.close(); // <10>
  // end::cachemanagerExample[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:24,代码来源:GettingStarted.java

示例14: startStopStart

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void startStopStart() throws Exception {
  cacheManager.init();

  assertThat(service.isStarted()).isTrue();

  Cache<Long, String> cache = cacheManager.getCache(CACHE, Long.class, String.class);
  cache.get(2L);
  assertThat(service.getCacheStatistics(CACHE).getCacheMisses()).isEqualTo(1);

  cacheManager.close();

  assertThat(service.isStarted()).isFalse();

  cacheManager.init();

  assertThat(service.isStarted()).isTrue();

  // We expect the stats to be reinitialized after a stop start
  assertThat(service.getCacheStatistics(CACHE).getCacheMisses()).isEqualTo(0);
  cache = cacheManager.getCache(CACHE, Long.class, String.class);
  cache.get(2L);
  assertThat(service.getCacheStatistics(CACHE).getCacheMisses()).isEqualTo(1);
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:DefaultStatisticsServiceTest.java

示例15: getContestLeaderboard

import org.ehcache.Cache; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<Map<String, Object>> getContestLeaderboard(int cid) {
    ContestEntity contestEntity = contestService.getContestByCid(cid);
    if (contestEntity == null) {
        return null;
    }
    int type = contestEntity.getType();
    Cache<Integer, Object> leaderboard = CacheController.getLeaderboard();
    List<Map<String, Object>> list = (List<Map<String, Object>>) leaderboard.get(cid);

    if (list!=null) {
        return list;
    }
    if (type == 0 || type == 1) {
        // 普通比赛
        list = contestUserService.getNormalContestRankList(cid);
    } else {
        // ACM
        list = contestUserService.getACMContestRankList(cid, DefaultConfig.ACM_PENALTY_TIME);
    }
    // 存放本次生成的基本信息
    Map<String, Object> meta = new HashMap<>(2);
    meta.put("name", contestEntity.getName());
    meta.put("cid", contestEntity.getCid());
    meta.put("total", list.size());
    meta.put("create_time", System.currentTimeMillis());
    list.add(0, meta);

    // 存放用户的排名信息
    Map<String, Object> userRank = new HashMap<>(list.size());
    for (int nowRank = 1; nowRank<list.size(); nowRank++) {
        Map<String, Object> temp = list.get(nowRank);
        userRank.put(String.valueOf(temp.get("uid")), nowRank);
    }
    list.add(1, userRank);

    leaderboard.put(cid, list);
    return list;
}
 
开发者ID:Eagle-OJ,项目名称:eagle-oj-api,代码行数:40,代码来源:LeaderboardService.java


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