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


Java Cache.put方法代码示例

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


在下文中一共展示了Cache.put方法的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: login

import org.ehcache.Cache; //导入方法依赖的package包/类
@ApiOperation("用户登入")
@PostMapping("/login")
public ResponseEntity login(@RequestBody @Valid IndexLoginFormat format) {
    UserEntity userEntity = userService.getUserByLogin(format.getEmail(),
            new Md5Hash(format.getPassword()).toString());
    if (userEntity == null)
        throw new WebErrorException("用户名密码错误");

    JSONArray array = userEntity.getPermission();
    Iterator<Object> it = array.iterator();
    Set<String> permission = new HashSet<>();
    while (it.hasNext()) {
        permission.add(it.next().toString());
    }
    String token = JWTUtil.sign(userEntity.getUid(), userEntity.getRole(), permission, userEntity.getPassword());
    Cache<String, String> authCache = CacheController.getAuthCache();
    authCache.put(token, userEntity.getPassword());

    return new ResponseEntity("登入成功", token);
}
 
开发者ID:Eagle-OJ,项目名称:eagle-oj-api,代码行数:21,代码来源:IndexController.java

示例4: 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

示例5: 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

示例6: main

import org.ehcache.Cache; //导入方法依赖的package包/类
public static void main(String[] args) {
  LOGGER.info("Creating clustered cache manager");
  final URI uri = create("terracotta://localhost:9510/clustered");
  try (CacheManager cacheManager = newCacheManagerBuilder()
          .with(cluster(uri).autoCreate().defaultServerResource("default-resource"))
          .withCache("basicCache",
                  newCacheConfigurationBuilder(Long.class, String.class,
                          heap(100).offheap(1, MB).with(clusteredDedicated(5, MB))))
          .build(true)) {
    Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class);

    LOGGER.info("Putting to cache");
    basicCache.put(1L, "da one!");

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

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

示例7: testCacheGet

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testCacheGet() throws Exception {
    final Cache<Object, Object> cache = getTestCache();
    final String key = generateRandomString();
    final String val = generateRandomString();

    cache.put(key, val);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    mock.expectedBodiesReceived(val);
    mock.expectedHeaderReceived(EhcacheConstants.ACTION_HAS_RESULT, true);
    mock.expectedHeaderReceived(EhcacheConstants.ACTION_SUCCEEDED, true);

    fluentTemplate()
        .withHeader(EhcacheConstants.ACTION, EhcacheConstants.ACTION_GET)
        .withHeader(EhcacheConstants.KEY, key)
        .withBody(val)
        .to("direct://start")
        .send();

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:EhcacheProducerTest.java

示例8: testCacheRemove

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testCacheRemove() throws Exception {
    final Cache<Object, Object> cache = getTestCache();
    final String key = generateRandomString();
    final String val = generateRandomString();

    cache.put(key, val);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    mock.expectedHeaderReceived(EhcacheConstants.ACTION_HAS_RESULT, false);
    mock.expectedHeaderReceived(EhcacheConstants.ACTION_SUCCEEDED, true);

    fluentTemplate()
        .withHeader(EhcacheConstants.ACTION, EhcacheConstants.ACTION_REMOVE)
        .withHeader(EhcacheConstants.KEY, key)
        .to("direct://start")
        .send();

    assertMockEndpointsSatisfied();

    assertFalse(cache.containsKey(key));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:EhcacheProducerTest.java

示例9: testCacheEventListener

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testCacheEventListener() {
  // tag::cacheEventListener[]
  CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration = CacheEventListenerConfigurationBuilder
      .newEventListenerConfiguration(new ListenerObject(), EventType.CREATED, EventType.UPDATED) // <1>
      .unordered().asynchronous(); // <2>

  final CacheManager manager = CacheManagerBuilder.newCacheManagerBuilder()
      .withCache("foo",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, ResourcePoolsBuilder.heap(10))
              .add(cacheEventListenerConfiguration) // <3>
      ).build(true);

  final Cache<String, String> cache = manager.getCache("foo", String.class, String.class);
  cache.put("Hello", "World"); // <4>
  cache.put("Hello", "Everyone"); // <5>
  cache.remove("Hello"); // <6>
  // end::cacheEventListener[]

  manager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:22,代码来源:GettingStarted.java

示例10: 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

示例11: testSerializers

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testSerializers() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/default-serializer.xml"));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();

  Cache<Long, Double> bar = cacheManager.getCache("bar", Long.class, Double.class);
  bar.put(1L, 1.0);
  assertThat(bar.get(1L), equalTo(1.0));

  Cache<String, String> baz = cacheManager.getCache("baz", String.class, String.class);
  baz.put("1", "one");
  assertThat(baz.get("1"), equalTo("one"));

  Cache<String, Object> bam = cacheManager.createCache("bam", newCacheConfigurationBuilder(String.class, Object.class, heap(10)).build());
  bam.put("1", "one");
  assertThat(bam.get("1"), equalTo((Object)"one"));

  cacheManager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例12: evictionTest

import org.ehcache.Cache; //导入方法依赖的package包/类
public void evictionTest() {
    CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(2L))
            .withEvictionAdvisor(new OddKeysEvictionAdvisor<Long, String>()).build();

    CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("cache", cacheConfiguration)
            .build(true);

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

    // Work with the cache
    cache.put(42L, "The Answer!");
    cache.put(41L, "The wrong Answer!");
    cache.put(39L, "The other wrong Answer!");

    cacheManager.close();
}
 
开发者ID:dzh,项目名称:jframe,代码行数:18,代码来源:TestEviction.java

示例13: testPersistentDiskCache

import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
  public void testPersistentDiskCache() throws Exception {
    CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
        ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).disk(10L, MemoryUnit.MB, true))
        .build();

    PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
        .with(new CacheManagerPersistenceConfiguration(new File(getClass().getClassLoader().getResource(".").toURI().getPath() + "/../../persistent-cache-data")))
        .withCache("persistent-cache", cacheConfiguration)
        .build(true);

    Cache<Long, String> cache = persistentCacheManager.getCache("persistent-cache", Long.class, String.class);

    // Comment the following line on subsequent run and see the test pass
    cache.put(42L, "That's the answer!");
    assertThat(cache.get(42L), is("That's the answer!"));

    // Uncomment the following line to nuke the disk store
//    persistentCacheManager.destroyCache("persistent-cache");

    persistentCacheManager.close();
  }
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:TieringTest.java

示例14: 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

示例15: swap

import org.ehcache.Cache; //导入方法依赖的package包/类
public double[] swap(Cache<String, double[]> cache, int cacheSize) throws IOException {

		String line, word;
		String[] vals;
		double[] vector = null, unk = null;
		int length = 0;

		try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(mMemFile)))) {

			while ((cacheSize != 0 || unk == null) && (line = reader.readLine()) != null) {

				vals = line.split(mVectorSeparator);
				length = vals.length - 1;
				word = vals[0];
				vector = new double[length];

				for (int j = 0; j < length; j++)
					vector[j] = Double.valueOf(vals[j + 1]);

				if (word.equals(DEF))
					unk = vector;

				else if (cacheSize > 0) {

					cache.put(word, vector);
					cacheSize--;
				}
			}
		}

		if (unk  == null)
			unk=new double[length];
		
		return unk;
	}
 
开发者ID:SI3P,项目名称:supWSD,代码行数:36,代码来源:WEVirtualMemory.java


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