Search in sources :

Example 31 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project uPortal by Jasig.

the class CacheManagementHelper method getAllCacheStatistics.

public Map<String, CacheStatistics> getAllCacheStatistics() {
    final Map<String, CacheStatistics> allCacheStatistics = new TreeMap<>(CaseInsenstivieStringComparator.INSTANCE);
    for (final String cacheName : this.cacheManager.getCacheNames()) {
        final Cache cache = this.cacheManager.getCache(cacheName);
        if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
            final CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
            final Statistics statistics = cache.getStatistics();
            final CacheStatistics cacheStatistics = new CacheStatistics();
            cacheStatistics.hits = statistics.getCacheHits();
            cacheStatistics.misses = statistics.getCacheMisses();
            cacheStatistics.size = statistics.getObjectCount();
            cacheStatistics.maxSize = (long) cacheConfiguration.getMaxElementsInMemory() + (long) cacheConfiguration.getMaxElementsOnDisk();
            allCacheStatistics.put(cacheName, cacheStatistics);
        }
    }
    return allCacheStatistics;
}
Also used : TreeMap(java.util.TreeMap) Statistics(net.sf.ehcache.Statistics) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 32 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project uPortal by Jasig.

the class CachingResourceLoaderImplTest method testCachedNotModified.

@Test
public void testCachedNotModified() throws Exception {
    final Resource doc1Resouce = new FileSystemResource(doc1);
    final CachingResourceLoaderImpl loader = new CachingResourceLoaderImpl();
    final Ehcache cache = createMock(Ehcache.class);
    final CachedResource<?> cachedResource = createMock(CachedResource.class);
    final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
    expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
    expect(cache.getInternalContext()).andReturn(null).anyTimes();
    expect(cache.getCacheConfiguration()).andReturn(new CacheConfiguration());
    final Element element = new Element("class path resource [CachingResourceLoaderImplTest_doc1.txt]", cachedResource);
    expect(cache.get(doc1Resouce)).andReturn(element);
    final long lastModified = doc1.lastModified();
    expect(cachedResource.getResource()).andReturn(doc1Resouce);
    expect(cachedResource.getLastCheckTime()).andReturn(0L);
    expect(cachedResource.getLastLoadTime()).andReturn(lastModified + TimeUnit.MINUTES.toMillis(5));
    expect(cachedResource.getAdditionalResources()).andReturn(Collections.EMPTY_MAP);
    cachedResource.setLastCheckTime(anyLong());
    cache.put(element);
    expectLastCall();
    replay(cache, cachedResource, elementsProvider);
    loader.setResourceCache(cache);
    loader.setResourcesElementsProvider(elementsProvider);
    final CachedResource<String> cachedResource1 = loader.getResource(doc1Resouce, StringResourceBuilder.INSTANCE);
    verify(cache, cachedResource, elementsProvider);
    assertNotNull(cachedResource1);
    assertTrue(cachedResource1 == cachedResource);
}
Also used : ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) Element(net.sf.ehcache.Element) LoadedResource(org.apereo.portal.utils.cache.resource.LoadedResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) CachedResource(org.apereo.portal.utils.cache.resource.CachedResource) Ehcache(net.sf.ehcache.Ehcache) FileSystemResource(org.springframework.core.io.FileSystemResource) CachingResourceLoaderImpl(org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Test(org.junit.Test)

Example 33 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project uPortal by Jasig.

the class CachingResourceLoaderImplTest method testUncachedLoadNoDigest.

@Test
public void testUncachedLoadNoDigest() throws Exception {
    final Resource doc1Resouce = new FileSystemResource(doc1);
    final CachingResourceLoaderImpl loader = new CachingResourceLoaderImpl();
    final Ehcache cache = createMock(Ehcache.class);
    final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
    expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
    expect(cache.getInternalContext()).andReturn(null).anyTimes();
    expect(cache.getCacheConfiguration()).andReturn(new CacheConfiguration());
    expect(cache.get(doc1Resouce)).andReturn(null);
    expect(cache.getQuiet(doc1Resouce)).andReturn(null);
    cache.put(anyObject(Element.class));
    expectLastCall();
    replay(cache, elementsProvider);
    loader.setResourceCache(cache);
    loader.setResourcesElementsProvider(elementsProvider);
    final CachedResource<String> cachedResource1 = loader.getResource(doc1Resouce, StringResourceBuilder.INSTANCE);
    verify(cache, elementsProvider);
    assertNotNull(cachedResource1);
    final String expected = IOUtils.toString(new FileReader(doc1));
    assertEquals(expected, cachedResource1.getCachedResource());
}
Also used : ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) Element(net.sf.ehcache.Element) LoadedResource(org.apereo.portal.utils.cache.resource.LoadedResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) CachedResource(org.apereo.portal.utils.cache.resource.CachedResource) Ehcache(net.sf.ehcache.Ehcache) FileReader(java.io.FileReader) FileSystemResource(org.springframework.core.io.FileSystemResource) CachingResourceLoaderImpl(org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Test(org.junit.Test)

Example 34 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project uPortal by Jasig.

the class CachingResourceLoaderImplTest method testCachedWithinInterval.

@Test
public void testCachedWithinInterval() throws Exception {
    final Resource doc1Resouce = new FileSystemResource(doc1);
    final CachingResourceLoaderImpl loader = new CachingResourceLoaderImpl();
    final Ehcache cache = createMock(Ehcache.class);
    final CachedResource<?> cachedResource = createMock(CachedResource.class);
    final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
    expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
    expect(cache.getInternalContext()).andReturn(null).anyTimes();
    expect(cache.getCacheConfiguration()).andReturn(new CacheConfiguration());
    expect(cache.get(doc1Resouce)).andReturn(new Element(doc1Resouce, cachedResource));
    expect(cachedResource.getLastCheckTime()).andReturn(System.currentTimeMillis());
    replay(cache, cachedResource, elementsProvider);
    loader.setResourceCache(cache);
    loader.setResourcesElementsProvider(elementsProvider);
    final CachedResource<String> cachedResource1 = loader.getResource(doc1Resouce, StringResourceBuilder.INSTANCE);
    verify(cache, cachedResource, elementsProvider);
    assertNotNull(cachedResource1);
    assertTrue(cachedResource1 == cachedResource);
}
Also used : ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) Element(net.sf.ehcache.Element) LoadedResource(org.apereo.portal.utils.cache.resource.LoadedResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) CachedResource(org.apereo.portal.utils.cache.resource.CachedResource) Ehcache(net.sf.ehcache.Ehcache) FileSystemResource(org.springframework.core.io.FileSystemResource) CachingResourceLoaderImpl(org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Test(org.junit.Test)

Example 35 with CacheConfiguration

use of net.sf.ehcache.config.CacheConfiguration in project uPortal by Jasig.

the class CachingResourceLoaderImplTest method testCachedModifiedLoad.

@Test
public void testCachedModifiedLoad() throws Exception {
    final Resource doc1Resouce = new FileSystemResource(doc1);
    final CachingResourceLoaderImpl loader = new CachingResourceLoaderImpl();
    final Ehcache cache = createMock(Ehcache.class);
    final CachedResource<?> cachedResource = createMock(CachedResource.class);
    final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
    expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
    expect(cache.getInternalContext()).andReturn(null).anyTimes();
    expect(cache.getCacheConfiguration()).andReturn(new CacheConfiguration());
    expect(cache.get(doc1Resouce)).andReturn(new Element(doc1Resouce, cachedResource));
    final long lastModified = doc1.lastModified();
    expect(cachedResource.getResource()).andReturn(doc1Resouce);
    expect(cachedResource.getLastCheckTime()).andReturn(lastModified - TimeUnit.MINUTES.toMillis(5));
    expect(cachedResource.getLastLoadTime()).andReturn(lastModified - TimeUnit.MINUTES.toMillis(5));
    cache.put(anyObject(Element.class));
    expectLastCall();
    replay(cache, cachedResource, elementsProvider);
    loader.setResourceCache(cache);
    loader.setResourcesElementsProvider(elementsProvider);
    final CachedResource<String> cachedResource1 = loader.getResource(doc1Resouce, StringResourceBuilder.INSTANCE);
    verify(cache, cachedResource, elementsProvider);
    assertNotNull(cachedResource1);
    final String expected = IOUtils.toString(new FileReader(doc1));
    assertEquals(expected, cachedResource1.getCachedResource());
}
Also used : ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) Element(net.sf.ehcache.Element) LoadedResource(org.apereo.portal.utils.cache.resource.LoadedResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) CachedResource(org.apereo.portal.utils.cache.resource.CachedResource) Ehcache(net.sf.ehcache.Ehcache) FileReader(java.io.FileReader) FileSystemResource(org.springframework.core.io.FileSystemResource) CachingResourceLoaderImpl(org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Test(org.junit.Test)

Aggregations

CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)71 Cache (net.sf.ehcache.Cache)26 CacheManager (net.sf.ehcache.CacheManager)16 Ehcache (net.sf.ehcache.Ehcache)14 Configuration (net.sf.ehcache.config.Configuration)14 Element (net.sf.ehcache.Element)9 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)8 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)6 Test (org.junit.Test)6 Resource (org.springframework.core.io.Resource)6 IOException (java.io.IOException)5 Bean (org.springframework.context.annotation.Bean)5 CachedResource (org.apereo.portal.utils.cache.resource.CachedResource)4 CachingResourceLoaderImpl (org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl)4 LoadedResource (org.apereo.portal.utils.cache.resource.LoadedResource)4 ResourcesElementsProvider (org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 FileReader (java.io.FileReader)3 URL (java.net.URL)3 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)3