use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.
the class OlapServiceImpl method getCache.
/**
* Returns a list of catalogs for the current session.
*
* <p>The cache is stored in the platform's caches in the region
* {@link #CATALOG_CACHE_REGION}. It is also segmented by
* locale, but we only return the correct sub-region according to the
* session passed as a parameter.
*/
@SuppressWarnings("unchecked")
protected synchronized List<IOlapService.Catalog> getCache(IPentahoSession session) {
// Create the cache region if necessary.
final ICacheManager cacheMgr = PentahoSystem.getCacheManager(session);
final Object cacheKey = makeCacheSubRegionKey(getLocale());
final Lock writeLock = cacheLock.writeLock();
try {
writeLock.lock();
if (!cacheMgr.cacheEnabled(CATALOG_CACHE_REGION)) {
// Create the region. This requires write access.
cacheMgr.addCacheRegion(CATALOG_CACHE_REGION);
}
if (cacheMgr.getFromRegionCache(CATALOG_CACHE_REGION, cacheKey) == null) {
// Create the sub-region. This requires write access.
cacheMgr.putInRegionCache(CATALOG_CACHE_REGION, cacheKey, new ArrayList<IOlapService.Catalog>());
}
return (List<IOlapService.Catalog>) cacheMgr.getFromRegionCache(CATALOG_CACHE_REGION, cacheKey);
} finally {
writeLock.unlock();
}
}
use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.
the class SessionCachingMetadataDomainRepositoryIT method tearDown.
public void tearDown() {
// Clean the cache
ICacheManager cacheManager = PentahoSystem.getCacheManager(null);
cacheManager.clearRegionCache(CACHE_NAME);
super.tearDown();
}
use of org.pentaho.platform.api.engine.ICacheManager in project data-access by pentaho.
the class AgileHelperTest method setUp.
@Before
public void setUp() throws SQLException, ObjectFactoryException {
Connection connection = mock(Connection.class);
DataSource dataSource = mock(DataSource.class);
when(dataSource.getConnection()).thenReturn(connection);
final ICacheManager manager = mock(ICacheManager.class);
when(manager.cacheEnabled(anyString())).thenReturn(true);
when(manager.getFromRegionCache(anyString(), any())).thenReturn(dataSource);
pentahoObjectFactory = mock(IPentahoObjectFactory.class);
when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return manager;
}
});
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
IApplicationContext context = mock(IApplicationContext.class);
when(context.getSolutionPath(anyString())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return (String) invocation.getArguments()[0];
}
});
PentahoSystem.setApplicationContext(context);
}
use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-kettle by pentaho.
the class RepositoryFactoryTest method testCachingFactoryConnect.
@Test
public void testCachingFactoryConnect() throws Exception {
ICacheManager cacheManager = mock(ICacheManager.class);
PentahoSystem.registerObject(cacheManager);
IPentahoSession session = new StandaloneSession("joe");
PentahoSessionHolder.setSession(session);
// Delegate is just a mock. connect will be a cache miss
IRepositoryFactory mockFactory = mock(IRepositoryFactory.class);
IRepositoryFactory.CachingRepositoryFactory cachingRepositoryFactory = new IRepositoryFactory.CachingRepositoryFactory(mockFactory);
cachingRepositoryFactory.connect("foo");
verify(mockFactory, times(1)).connect("foo");
// Test with Cache Hit
Repository mockRepository = mock(Repository.class);
when(cacheManager.cacheEnabled(IRepositoryFactory.CachingRepositoryFactory.REGION)).thenReturn(true);
when(cacheManager.getFromRegionCache(IRepositoryFactory.CachingRepositoryFactory.REGION, "joe")).thenReturn(mockRepository);
Repository repo = cachingRepositoryFactory.connect("foo");
assertThat(repo, sameInstance(mockRepository));
}
Aggregations