Package com.avaje.ebean.cache

Examples of com.avaje.ebean.cache.ServerCache


    cachedBean.getCountries().add(Ebean.find(Country.class, "AU"));

    Ebean.save(cachedBean);

    // clear the cache
    ServerCache cachedBeanCountriesCache = cacheManager.getCollectionIdsCache(OCachedBean.class, "countries");
    cachedBeanCountriesCache.clear();
    Assert.assertEquals(0, cachedBeanCountriesCache.size());

    // load the cache
    OCachedBean dummyLoad = Ebean.find(OCachedBean.class, cachedBean.getId());
    List<Country> dummyCountries = dummyLoad.getCountries();
    Assert.assertEquals(2, dummyCountries.size());

    // assert that the cache contains the expected entry
    Assert.assertEquals("countries cache now loaded with 1 entry", 1, cachedBeanCountriesCache.size());
    CachedManyIds dummyEntry = (CachedManyIds) cachedBeanCountriesCache.get(dummyLoad.getId());
    Assert.assertNotNull(dummyEntry);
    Assert.assertEquals("2 ids in the entry", 2, dummyEntry.getIdList().size());
    Assert.assertTrue(dummyEntry.getIdList().contains("NZ"));
    Assert.assertTrue(dummyEntry.getIdList().contains("AU"));
   
   
    // act - this should invalidate our cache entry
    OCachedBean update = new OCachedBean();
    update.setId(cachedBean.getId());
    update.setName("modified");
    update.getCountries().add(Ebean.find(Country.class, "AU"));

    Ebean.update(update);
   
    Assert.assertEquals("countries entry still there (but updated)", 1, cachedBeanCountriesCache.size());
   

    CachedManyIds cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(update.getId());

    // assert cache updated
    Assert.assertEquals(1, cachedManyIds.getIdList().size());
    Assert.assertFalse(cachedManyIds.getIdList().contains("NZ"));
    Assert.assertTrue(cachedManyIds.getIdList().contains("AU"));
View Full Code Here


  @SuppressWarnings("unchecked")
  public void test() {

    ResetBasicData.reset();

    ServerCache customerCache = Ebean.getServerCacheManager().getQueryCache(Customer.class);
    customerCache.clear();

    List<Customer> list = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(true).where()
        .ilike("name", "Rob").findList();

    BeanCollection<Customer> bc = (BeanCollection<Customer>) list;
View Full Code Here

    ResetBasicData.reset();

    Ebean.runCacheWarming(Country.class);

    ServerCache countryCache = Ebean.getServerCacheManager().getBeanCache(Country.class);

    Assert.assertTrue(countryCache.size() > 0);

    // inserts don't remove from bean cache
    Ebean.externalModification("o_country", true, false, false);
    Assert.assertTrue(countryCache.size() > 0);

    // updates flush cache
    Ebean.externalModification("o_country", false, true, false);
    Assert.assertEquals(0, countryCache.size());

    Ebean.runCacheWarming(Country.class);
    Assert.assertTrue(countryCache.size() > 0);

    // deletes flush cache
    Ebean.externalModification("o_country", false, false, true);
    Assert.assertEquals(0, countryCache.size());

    Ebean.runCacheWarming(Country.class);
    Assert.assertTrue(countryCache.size() > 0);

    ServerCacheManager serverCacheManager = Ebean.getServerCacheManager();
    serverCacheManager.clearAll();
    Assert.assertEquals(0, countryCache.size());

    Ebean.runCacheWarming(Country.class);
    Assert.assertTrue(countryCache.size() > 0);

    Ebean.getServerCacheManager().clear(Country.class);
    Assert.assertEquals(0, countryCache.size());

    Ebean.runCacheWarming(Country.class);
    int cacheSize = countryCache.size();
    Assert.assertTrue("cacheSize: " + cacheSize, cacheSize > 0);

    SqlUpdate sqlUpdate = Ebean
        .createSqlUpdate("update o_country set name = :name where code = :code");
    sqlUpdate.setParameter("name", "Aotearoa");
    sqlUpdate.setParameter("code", "NZ");

    // this should just clear the entire country cache
    int rows = sqlUpdate.execute();
    Assert.assertEquals(1, rows);
    Assert.assertEquals(0, countryCache.size());

    // set it back...
    sqlUpdate.setParameter("name", "New Zealand");
    sqlUpdate.setParameter("code", "NZ");
    rows = sqlUpdate.execute();
View Full Code Here

  public void test() {

    ResetBasicData.reset();

    Ebean.getServerCacheManager().clear(Country.class);
    ServerCache countryCache = Ebean.getServerCacheManager().getBeanCache(Country.class);

    Ebean.runCacheWarming(Country.class);
    Assert.assertTrue(countryCache.size() > 0);

    // reset the statistics
    countryCache.getStatistics(true);

    Country c0 = Ebean.getReference(Country.class, "NZ");
    ServerCacheStatistics statistics = countryCache.getStatistics(false);
    int hc = statistics.getHitCount();
    Assert.assertEquals(1, hc);
    Assert.assertNotNull(c0);

    // Country c1 = Ebean.getReference(Country.class, "NZ");
View Full Code Here

  @Test
  public void test() {
   
    ResetBasicData.reset();
   
    ServerCache cache = Ebean.getServerCacheManager().getQueryCache(Country.class);
    cache.clear();

    Assert.assertEquals(0, cache.getStatistics(false).getSize());
   
    List<Country> countryList0 = Ebean.find(Country.class)
      .setUseQueryCache(true)
      .order().asc("name")
      .findList();
   
    Assert.assertEquals(1, cache.getStatistics(false).getSize());
    Assert.assertTrue(countryList0.size() > 0);
   
    List<Country> countryList1 = Ebean.find(Country.class)
        .setUseQueryCache(true)
        .order().asc("name")
        .findList();
     
    ServerCacheStatistics statistics = cache.getStatistics(false);
    Assert.assertEquals(1, statistics.getSize());
    Assert.assertEquals(1, statistics.getHitCount());
    Assert.assertSame(countryList1, countryList0);
   
    Country nz = Ebean.find(Country.class, "NZ");
    nz.setName("New Zealandia");
    Ebean.save(nz);
   
    statistics = cache.getStatistics(false);
    Assert.assertEquals(0, statistics.getSize());
   
    List<Country> countryList2 = Ebean.find(Country.class)
        .setUseQueryCache(true)
        .order().asc("name")
View Full Code Here

  
    EbeanServer server = Ebean.getServer(null);
    ServerCacheManager serverCacheManager = server.getServerCacheManager();
   
    // get cache, clear the cache and statistics
    ServerCache beanCache = serverCacheManager.getBeanCache(EInvoice.class);
    beanCache.clear();
    beanCache.getStatistics(true);
   
    // fetch and load the cache
    EInvoice invoice4 = Ebean.find(EInvoice.class)
        .where().idEq(invoice.getId())
        .setUseCache(true)
        .findUnique();
   
    Assert.assertNotNull(invoice4);
   
    ServerCacheStatistics statistics = beanCache.getStatistics(false);

    Assert.assertEquals(1, statistics.getSize());
    Assert.assertEquals(0, statistics.getHitCount());

    // fetch out of the cache this time
    EInvoice invoice5 = Ebean.find(EInvoice.class)
        .where().idEq(invoice.getId())
        .setUseCache(true)
        .findUnique();

    Assert.assertNotNull(invoice5);
   
    statistics = beanCache.getStatistics(false);
    Assert.assertEquals(1, statistics.getSize());
    Assert.assertEquals(1, statistics.getHitCount());

    billAddress = invoice5.getBillAddress();
   
View Full Code Here

    ResetBasicData.reset();

    // Need to make sure the customer cache is cleared for the later
    // asserts on the lazy loading
    ServerCache custCache = Ebean.getServerCacheManager().getBeanCache(Customer.class);
    custCache.clear();

    Query<Order> query = Ebean.find(Order.class).select("status")
    // .join("details","+query(10)")
        .fetch("customer", "+lazy(10) name, status").fetch("customer.contacts").orderBy().asc("id");
    // .join("customer.billingAddress");
View Full Code Here

    Assert.assertTrue(beanDescriptor.isCacheSharableBeans());

    ServerCacheManager serverCacheManager = server.getServerCacheManager();
    serverCacheManager.clear(Country.class);

    ServerCache beanCache = serverCacheManager.getBeanCache(Country.class);
    Assert.assertEquals(0, beanCache.size());

    Country nz1 = Ebean.getReference(Country.class, "NZ");
    Assert.assertEquals(0, beanCache.size());

    // has the effect of loading the cache via lazy loading
    nz1.getName();
    Assert.assertEquals(1, beanCache.size());

    Country nz2 = Ebean.getReference(Country.class, "NZ");
    Country nz2b = Ebean.getReference(Country.class, "NZ");

    Country nz3 = Ebean.find(Country.class, "NZ");
View Full Code Here

  /**
   * Return the cache for a given bean type.
   */
  public ServerCache getCache(String cacheKey) {

    ServerCache cache = concMap.get(cacheKey);
    if (cache != null) {
      return cache;
    }
    synchronized (monitor) {
      cache = synchMap.get(cacheKey);
View Full Code Here

    }
  }

  public void clearCache(String cacheKey) {

    ServerCache cache = concMap.get(cacheKey);
    if (cache != null) {
      cache.clear();
    }
  }
View Full Code Here

TOP

Related Classes of com.avaje.ebean.cache.ServerCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.