Java 类net.sf.ehcache.CacheManager 实例源码

项目:mycat-src-1.6.1-RELEASE    文件:EnchachePooFactory.java   
@Override
public CachePool createCachePool(String poolName, int cacheSize,
        int expiredSeconds) {
    CacheManager cacheManager = CacheManager.create();
    Cache enCache = cacheManager.getCache(poolName);
    if (enCache == null) {

        CacheConfiguration cacheConf = cacheManager.getConfiguration()
                .getDefaultCacheConfiguration().clone();
        cacheConf.setName(poolName);
        if (cacheConf.getMaxEntriesLocalHeap() != 0) {
            cacheConf.setMaxEntriesLocalHeap(cacheSize);
        } else {
            cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
        }
        cacheConf.setTimeToIdleSeconds(expiredSeconds);
        Cache cache = new Cache(cacheConf);
        cacheManager.addCache(cache);
        return new EnchachePool(poolName,cache,cacheSize);
    } else {
        return new EnchachePool(poolName,enCache,cacheSize);
    }
}
项目:bootstrap    文件:ConfigurationResourceTest.java   
@Test
public void update() {
    final SystemConfiguration value = em.createQuery("FROM SystemConfiguration WHERE name=:name", SystemConfiguration.class)
            .setParameter("name", "test-key5").getSingleResult();
    em.clear();
    Assert.assertNotEquals("new-value-db5", value.getValue());
    Assert.assertEquals("value-db5", resource.get("test-key5"));
    resource.saveOrUpdate("test-key5", "new-value-db5");

    // Check the data from the cache
    Assert.assertEquals("new-value-db5", resource.get("test-key5"));
    SystemConfiguration newValue = em.createQuery("FROM SystemConfiguration WHERE name=:name", SystemConfiguration.class)
            .setParameter("name", "test-key5").getSingleResult();

    // Check data is encrypted
    Assert.assertNotEquals("new-value-db5", newValue.getValue());
    Assert.assertEquals("new-value-db5", cryptoHelper.decrypt(newValue.getValue()));

    // Check previous id is kept
    Assert.assertEquals(value.getId(), newValue.getId());

    // Check persistence of data and cache
    CacheManager.getInstance().getCache("configuration").removeAll();
    Assert.assertEquals("new-value-db5", resource.get("test-key5"));
}
项目:product    文件:ProductlevelAction.java   
@At
@Ok("json")
public Map<String,String> save(@Param("action")int action,
                            @Param("..")Productlevel productlevel){
    Object rtnObject;
    if (productlevel.getId() == null || productlevel.getId() == 0) {
        rtnObject = productlevelService.dao().insert(productlevel);
    }else{
        if (action == 3) {
            productlevel.setId(null);
            rtnObject = productlevelService.dao().insert(productlevel);
        }else{
            rtnObject = productlevelService.dao().updateIgnoreNull(productlevel);
        }
    }
    CacheManager.getInstance().getCache(ProductlevelService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_productlevel", true);

}
项目:product    文件:AporialevelAction.java   
@At
@Ok("json")
public Map<String, String> save(@Param("action") int action,
                                @Param("..") Aporialevel aporialevel) {
    Object rtnObject;
    if (aporialevel.getId() == null || aporialevel.getId() == 0) {
        rtnObject = aporialevelService.dao().insert(aporialevel);
    } else {
        if (action == 3) {
            aporialevel.setId(null);
            rtnObject = aporialevelService.dao().insert(aporialevel);
        } else {
            rtnObject = aporialevelService.dao().updateIgnoreNull(aporialevel);
        }
    }
    CacheManager.getInstance().getCache(AporialevelService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_aporialevel", true);

}
项目:plugin-id    文件:AbstractContainerResourceTest.java   
@Before
public void prepareData() throws IOException {
    persistEntities("csv",
            new Class[] { DelegateOrg.class, ContainerScope.class, CacheCompany.class, CacheUser.class, CacheGroup.class, CacheMembership.class },
            StandardCharsets.UTF_8.name());
    CacheManager.getInstance().getCache("container-scopes").removeAll();

    iamProvider = Mockito.mock(IamProvider.class);
    final IamConfiguration configuration = Mockito.mock(IamConfiguration.class);
    Mockito.when(iamProvider.getConfiguration()).thenReturn(configuration);
    userRepository = Mockito.mock(IUserRepository.class);
    groupRepository = Mockito.mock(IGroupRepository.class);
    companyRepository = Mockito.mock(ICompanyRepository.class);
    Mockito.when(configuration.getUserRepository()).thenReturn(userRepository);
    Mockito.when(configuration.getCompanyRepository()).thenReturn(companyRepository);
    Mockito.when(configuration.getGroupRepository()).thenReturn(groupRepository);
}
项目:product    文件:TechnicalpointAction.java   
@At
@Ok("json")
public Map<String,String> save(@Param("action")int action,
                            @Param("..")Technicalpoint technicalpoint){
    Object rtnObject;
    if (technicalpoint.getId() == null || technicalpoint.getId() == 0) {
        rtnObject = technicalpointService.dao().insert(technicalpoint);
    }else{
        if (action == 3) {
            technicalpoint.setId(null);
            rtnObject = technicalpointService.dao().insert(technicalpoint);
        }else{
            rtnObject = technicalpointService.dao().updateIgnoreNull(technicalpoint);
        }
    }
    CacheManager.getInstance().getCache(TechnicalpointService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_technicalpoint", true);

}
项目:product    文件:AporiaAction.java   
@At
@Ok("json")
public Map<String,String> save(@Param("action")int action,
                            @Param("..")Aporia aporia){
    Object rtnObject;
    if (aporia.getId() == null || aporia.getId() == 0) {
        rtnObject = aporiaService.dao().insert(aporia);
    }else{
        if (action == 3) {
            aporia.setId(null);
            rtnObject = aporiaService.dao().insert(aporia);
        }else{
            rtnObject = aporiaService.dao().updateIgnoreNull(aporia);
        }
    }
    CacheManager.getInstance().getCache(AporiaService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_aporia", true);

}
项目:product    文件:ProductAction.java   
@At
@Ok("json")
public Map<String,String> save(@Param("action")int action,
                            @Param("..")Product product){
    Object rtnObject;
    if (product.getId() == null || product.getId() == 0) {
        rtnObject = productService.dao().insert(product);
    }else{
        if (action == 3) {
            product.setId(null);
            rtnObject = productService.dao().insert(product);
        }else{
            rtnObject = productService.dao().updateIgnoreNull(product);
        }
    }
    CacheManager.getInstance().getCache(ProductService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_product", true);

}
项目:springboot-shiro-cas-mybatis    文件:TicketRegistryDecoratorTests.java   
@Test
public void verifyEhCacheTicketRegistryWithClearPass() {
    final Cache serviceTicketsCache = new Cache("serviceTicketsCache", 200, false, false, 100, 100);
    final Cache ticketGrantingTicketCache = new Cache("ticketGrantingTicketCache", 200, false, false, 100, 100);

    final CacheManager manager = new CacheManager(this.getClass().getClassLoader().getResourceAsStream("ehcacheClearPass.xml"));
    manager.addCache(serviceTicketsCache);
    manager.addCache(ticketGrantingTicketCache);

    final Map<String, String> map = new HashMap<>();

    final TicketRegistry ticketRegistry = new EhCacheTicketRegistry(serviceTicketsCache, ticketGrantingTicketCache);
    final TicketRegistryDecorator decorator = new TicketRegistryDecorator(ticketRegistry, map);
    assertNotNull(decorator);

    assertEquals(decorator.serviceTicketCount(), 0);
    assertEquals(decorator.sessionCount(), 0);

    manager.removalAll();
    manager.shutdown();

}
项目:otus_java_2017_04    文件:EhcacheHelper.java   
static Cache createLifeCache(CacheManager manager, String name) {
    CacheConfiguration configuration = new CacheConfiguration(name, MAX_ENTRIES);
    configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO)
            .timeToLiveSeconds(LIFE_TIME_SEC);

    Cache cache = new Cache(configuration);
    manager.addCache(cache);

    return cache;
}
项目:crm    文件:LinktypeAction.java   
@At
@Ok("json")
public Map<String,String> save( @Param("..")Linktype linktype){
    Object rtnObject;
    if (linktype.getId() == null || linktype.getId() == 0) {
        rtnObject = linktypeService.dao().insert(linktype);
    }else{
        rtnObject = linktypeService.dao().updateIgnoreNull(linktype);
    }
    CacheManager.getInstance().getCache(LinktypeService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_linktype", true);

}
项目:crm    文件:EmployeeService.java   
public int listCount(Cnd c)
{
    Long num = 0L;
    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(CACHE_COUNT_KEY) == null)
    {
        num = Long.valueOf(this.count(c));
        cache.put(new Element(CACHE_COUNT_KEY, num));
    }else{
        num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue();
    }
    return num.intValue();
}
项目:crm    文件:EmployeeAction.java   
@At
@Ok("json")
public Map<String,String> save( @Param("..")Employee employee){
    Object rtnObject;
    if (employee.getId() == null || employee.getId() == 0) {
        rtnObject = employeeService.dao().insert(employee);
    }else{
        rtnObject = employeeService.dao().updateIgnoreNull(employee);
    }
    CacheManager.getInstance().getCache(EmployeeService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_employee", true);

}
项目:plugin-id-ldap    文件:LdapPluginResourceTest.java   
@Before
public void prepareData() throws IOException {
    persistEntities(
            "csv", new Class[] { DelegateOrg.class, ContainerScope.class, CacheCompany.class, CacheUser.class, CacheGroup.class,
                    CacheMembership.class, Project.class, Node.class, Parameter.class, Subscription.class, ParameterValue.class, 
                    CacheProjectGroup.class },
            StandardCharsets.UTF_8.name());
    CacheManager.getInstance().getCache("container-scopes").removeAll();

    // Only with Spring context
    this.subscription = getSubscription("gStack", IdentityResource.SERVICE_KEY);

    // Coverage only
    resource.getKey();
}
项目:plugin-id-ldap    文件:LdapPluginResourceTest.java   
/**
 * Reload the LDAP cache
 */
private void reloadLdapCache() {
    // Ensure LDAP cache is loaded
    CacheManager.getInstance().getCache("ldap").removeAll();
    cache.getLdapData();
    em.flush();
    em.clear();
}
项目:cas-server-4.2.1    文件:EhcacheBackedMapTests.java   
@Before
public void prep() {
    this.manager = CacheManager.create();
    this.manager.addCache("cascache");
    this.cache = this.manager.getCache("cascache");
    this.map = new EhcacheBackedMap(this.cache);
}
项目:otus_java_2017_04    文件:EhcacheHelper.java   
static Cache createEternalCache(CacheManager manager, String name) {
    CacheConfiguration configuration = new CacheConfiguration(name, MAX_ENTRIES);
    configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO)
            .eternal(true);

    Cache cache = new Cache(configuration);
    manager.addCache(cache);

    return cache;
}
项目:product    文件:ProductlevelService.java   
public int listCount(Condition c)
{
    Long num = 0L;
    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(CACHE_COUNT_KEY) == null)
    {
        num = Long.valueOf(this.count(c));
        cache.put(new Element(CACHE_COUNT_KEY, num));
    }else{
        num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue();
    }
    return num.intValue();
}
项目:crm    文件:PartyAction.java   
@At
@Ok("json")
public Map<String,String> del(@Param("id")Long id)
{
    int num =  partyService.delete(id);
    CacheManager.getInstance().getCache(PartyService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((num > 0) ? true : false , "tab_party",false);
}
项目:product    文件:LanguageService.java   
public int listCount(Condition c)
{
    Long num = 0L;
    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(CACHE_COUNT_KEY) == null)
    {
        num = Long.valueOf(this.count(c));
        cache.put(new Element(CACHE_COUNT_KEY, num));
    }else{
        num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue();
    }
    return num.intValue();
}
项目:product    文件:ProductgroupService.java   
public List<Productgroup> queryCache(Condition c,Page p)
{
    List<Productgroup> list_productgroup = null;
    String cacheKey = "productgroup_list_" + p.getPageCurrent();

    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(cacheKey) == null)
    {
        list_productgroup = this.query(c, p);
        cache.put(new Element(cacheKey, list_productgroup));
    }else{
        list_productgroup = (List<Productgroup>)cache.get(cacheKey).getObjectValue();
    }
    return list_productgroup;
}
项目:product    文件:ProductgroupService.java   
public int listCount(Condition c)
{
    Long num = 0L;
    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(CACHE_COUNT_KEY) == null)
    {
        num = Long.valueOf(this.count(c));
        cache.put(new Element(CACHE_COUNT_KEY, num));
    }else{
        num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue();
    }
    return num.intValue();
}
项目:otus_java_2017_10    文件:EhcacheHelper.java   
static Cache createIdleCache(CacheManager manager, String name) {
    return createCache(
            manager,
            name,
            configuration -> configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO)
                    .timeToIdleSeconds(IDLE_TIME_SEC));
}
项目:product    文件:AporialevelService.java   
public List<Aporialevel> queryCache(Condition c,Page p)
{
    List<Aporialevel> list_aporialevel = null;
    String cacheKey = "aporialevel_list_" + p.getPageCurrent();

    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(cacheKey) == null)
    {
        list_aporialevel = this.query(c, p);
        cache.put(new Element(cacheKey, list_aporialevel));
    }else{
        list_aporialevel = (List<Aporialevel>)cache.get(cacheKey).getObjectValue();
    }
    return list_aporialevel;
}
项目:product    文件:AporialevelService.java   
public int listCount(Condition c)
{
    Long num = 0L;
    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(CACHE_COUNT_KEY) == null)
    {
        num = Long.valueOf(this.count(c));
        cache.put(new Element(CACHE_COUNT_KEY, num));
    }else{
        num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue();
    }
    return num.intValue();
}
项目:product    文件:CodeService.java   
public List<Code> queryCache(Condition c,Page p)
{
    List<Code> list_code = null;
    String cacheKey = "code_list_" + p.getPageCurrent();

    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(cacheKey) == null)
    {
        list_code = this.query(c, p);
        cache.put(new Element(cacheKey, list_code));
    }else{
        list_code = (List<Code>)cache.get(cacheKey).getObjectValue();
    }
    return list_code;
}
项目:product    文件:CodeService.java   
public int listCount(Condition c)
{
    Long num = 0L;
    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(CACHE_COUNT_KEY) == null)
    {
        num = Long.valueOf(this.count(c));
        cache.put(new Element(CACHE_COUNT_KEY, num));
    }else{
        num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue();
    }
    return num.intValue();
}
项目:parabuild-ci    文件:SupportService.java   
/**
 * Attempts to init cache to default values ignoring
 * exceptions.
 */
private void initCacheHard() {
  try {
    CacheManager.create();
  } catch (Exception e) {
    log.error("Error creating cache", e);
  }
}
项目:kaltura-ce-sakai-extension    文件:KalturaTestWebservices.java   
protected void onSetUpInTransaction() {

        // make a cache
        CacheManager cacheManager = CacheManager.create();
        if (! cacheManager.cacheExists("ehcache.sakai.kaltura.entries")) {
            cacheManager.addCache("ehcache.sakai.kaltura.entries");
        }
        Ehcache entriesCache = cacheManager.getCache("ehcache.sakai.kaltura.entries");

        // create and setup the object to be tested
        external = new ExternalLogicStub();
        service = new KalturaAPIService();
        service.setExternal(external);
        service.setEntriesCache(entriesCache);
        service.setOffline(true); // for testing we do not try to fetch real data

        // run the init
        external.currentUserId = FakeDataPreload.ADMIN_USER_ID; // DEFAULT ADMIN
        // UNICON settings for testing
        external.config.put("kaltura.partnerid", 166762);
        external.config.put("kaltura.adminsecret", "26d08a0ba54c911492bbc7599028295f");
        external.config.put("kaltura.secret", "6e4755b613a38b19e4cfb5d7405ed170");

        service.testWSInit(); // SPECIAL INIT

        service.getKalturaClient();
    }
项目:product    文件:StudioAction.java   
@At
@Ok("json")
public Map<String,String> del(@Param("id")Long id)
{
    int num =  studioService.delete(id);
    CacheManager.getInstance().getCache(StudioService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((num > 0) ? true : false , "tab_studio",false);
}
项目:crm    文件:MaritalAction.java   
@At
@Ok("json")
public Map<String,String> save( @Param("..")Marital marital){
    Object rtnObject;
    if (marital.getId() == null || marital.getId() == 0) {
        rtnObject = maritalService.dao().insert(marital);
    }else{
        rtnObject = maritalService.dao().updateIgnoreNull(marital);
    }
    CacheManager.getInstance().getCache(MaritalService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_marital", true);

}
项目:product    文件:CodeAction.java   
@At
@Ok("json")
public Map<String,String> del(@Param("id")Long id)
{
    int num =  codeService.delete(id);
    CacheManager.getInstance().getCache(CodeService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((num > 0) ? true : false , "tab_code",false);
}
项目:crm    文件:LinkmanAction.java   
@At
@Ok("json")
public Map<String,String> del(@Param("id")Long id)
{
    int num =  linkmanService.delete(id);
    CacheManager.getInstance().getCache(LinkmanService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((num > 0) ? true : false , "tab_linkman",false);
}
项目:product    文件:ProductgroupAction.java   
@At
@Ok("json")
public Map<String,String> del(@Param("id")Long id)
{
    int num =  productgroupService.delete(id);
    CacheManager.getInstance().getCache(ProductgroupService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((num > 0) ? true : false , "tab_productgroup",false);
}
项目:cas-server-4.2.1    文件:PoolingLdaptiveResourceCRLFetcherTests.java   
@Test
public void getCrlFromLdapWithNoCaching() throws Exception {
    for (int i = 0; i < 10; i++) {
        CacheManager.getInstance().removeAllCaches();
        final Cache cache = new Cache("crlCache-1", 100, false, false, 20, 10);
        CacheManager.getInstance().addCache(cache);
        final CRLDistributionPointRevocationChecker checker = new CRLDistributionPointRevocationChecker(cache, fetcher);
        checker.setThrowOnFetchFailure(true);
        checker.setUnavailableCRLPolicy(new AllowRevocationPolicy());
        final X509Certificate cert = CertUtils.readCertificate(new ClassPathResource("ldap-crl.crt"));
        checker.init();
        checker.check(cert);
    }
}
项目:crm    文件:UnitAction.java   
@At
@Ok("json")
public Map<String,String> save( @Param("..")Unit unit){
    Object rtnObject;
    if (unit.getId() == null || unit.getId() == 0) {
        rtnObject = unitService.dao().insert(unit);
    }else{
        rtnObject = unitService.dao().updateIgnoreNull(unit);
    }
    CacheManager.getInstance().getCache(UnitService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_unit", true);

}
项目:crm    文件:EducationService.java   
public int listCount(Cnd c)
{
    Long num = 0L;
    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(CACHE_COUNT_KEY) == null)
    {
        num = Long.valueOf(this.count(c));
        cache.put(new Element(CACHE_COUNT_KEY, num));
    }else{
        num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue();
    }
    return num.intValue();
}
项目:crm    文件:ContractAction.java   
@At
@Ok("json")
public Map<String,String> save( @Param("..")Contract contract){
    Object rtnObject;
    if (contract.getId() == null || contract.getId() == 0) {
        rtnObject = contractService.dao().insert(contract);
    }else{
        rtnObject = contractService.dao().updateIgnoreNull(contract);
    }
    CacheManager.getInstance().getCache(ContractService.CACHE_NAME).removeAll();
    return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_contract", true);

}
项目:cas-server-4.2.1    文件:ClearPassControllerTests.java   
@Before
public void prep() {
    this.manager = CacheManager.create();
    this.manager.addCache("cascache");
    this.cache = this.manager.getCache("cascache");
    this.map = new EhcacheBackedMap(this.cache);
}
项目:crm    文件:PartyService.java   
public int listCount(Cnd c)
{
    Long num = 0L;
    Cache cache = CacheManager.getInstance().getCache(CACHE_NAME);
    if(cache.get(CACHE_COUNT_KEY) == null)
    {
        num = Long.valueOf(this.count(c));
        cache.put(new Element(CACHE_COUNT_KEY, num));
    }else{
        num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue();
    }
    return num.intValue();
}