Package org.dspace.services.model

Examples of org.dspace.services.model.Cache


     */
    public void queueEvent(Event event) {
        validateEvent(event);

        // get the cache
        Cache queueCache = this.cachingService.getCache(QUEUE_CACHE_NAME, new CacheConfig(CacheScope.REQUEST));

        // put the event in the queue if this is in a request
        if (requestService.getCurrentRequestId() != null) {
            // create a key which is orderable and unique
            String key = System.currentTimeMillis() + ":" + queueCache.size() + ":" + event.getId();
            queueCache.put(key, event);
        } else {
            // no request so fire the event immediately
            log.info("No request to queue this event ("+event+") so firing immediately");
            fireEvent(event);
        }
View Full Code Here


     *
     * @return the number of events which were fired
     */
    protected int fireQueuedEvents() {
        int fired = 0;
        Cache queueCache = this.cachingService.getCache(QUEUE_CACHE_NAME, new CacheConfig(CacheScope.REQUEST));

        List<String> eventIds = queueCache.getKeys();
        Collections.sort(eventIds); // put it in the order they were added (hopefully)
        if (eventIds.size() > 0) {
            for (String eventId : eventIds) {
                Event event = (Event) queueCache.get(eventId);
                fireEvent(event);
                fired++;
            }
        }
        queueCache.clear();
        return fired;
    }
View Full Code Here

     * Clears all events for the current request.
     *
     * @return the number of events that were cleared
     */
    protected int clearQueuedEvents() {
        Cache queueCache = this.cachingService.getCache(QUEUE_CACHE_NAME, new CacheConfig(CacheScope.REQUEST));
        int cleared = queueCache.size();
        queueCache.clear();
        return cleared;
    }
View Full Code Here

     * Test method for {@link org.dspace.services.caching.CachingServiceImpl#getCache(java.lang.String, org.dspace.services.model.CacheConfig)}.
     */
    @Test
    public void testGetCache() {
        // test getting ehcache from the config
        Cache cache = cachingService.getCache("org.dspace.caching.MemOnly", null);
        assertNotNull(cache);
        assertEquals("org.dspace.caching.MemOnly", cache.getName());

        // test getting ehcache from bean
        Cache sampleCache = cachingService.getCache("org.sakaiproject.caching.test.SampleCache", null);
        assertNotNull(sampleCache);
        assertEquals("org.sakaiproject.caching.test.SampleCache", sampleCache.getName());

        // test making new caches
        Cache c1 = cachingService.getCache("org.dspace.aztest", null);
        assertNotNull(c1);
        assertEquals("org.dspace.aztest", c1.getName());
        assertEquals(CacheScope.INSTANCE, c1.getConfig().getCacheScope());
        assertTrue(c1 instanceof EhcacheCache);

        requestService.startRequest();

        Cache rc1 = cachingService.getCache("org.dspace.request.cache1", new CacheConfig(CacheScope.REQUEST));
        assertNotNull(rc1);
        assertEquals("org.dspace.request.cache1", rc1.getName());
        assertEquals(CacheScope.REQUEST, rc1.getConfig().getCacheScope());
        assertTrue(rc1 instanceof MapCache);

        requestService.endRequest(null);

        // try getting the same one twice
        Cache c2 = cachingService.getCache("org.dspace.aztest", null);
        assertNotNull(c2);
        assertEquals(c1, c2);
       
        //trash the references
        cache = sampleCache = c1 = rc1 = c2 = null;
View Full Code Here

        List<Cache> caches = cachingService.getCaches();
        assertNotNull(caches);
        int curSize = caches.size();
        assertTrue(curSize > 0);

        Cache memCache = cachingService.getCache("org.dspace.caching.MemOnly", null);
        assertNotNull(memCache);
        assertTrue(caches.contains(memCache));

        // This should create a new cache (as cache name is unique)
        Cache c1 = cachingService.getCache("org.dspace.timtest.newcache", null);
        assertNotNull(c1);

        // Test that new cache was created and total caches increases by one
        caches = cachingService.getCaches();
        assertNotNull(caches);
View Full Code Here

    @Test
    public void testResetCaches() {
        cachingService.resetCaches();

        // now add new cache
        Cache c1 = cachingService.getCache("org.dspace.aztest.new", null);
        assertNotNull(c1);
        c1.put("AZ", "aaron.zeckoski");
        c1.put("BZ", "becky.zeckoski");
        assertEquals("aaron.zeckoski", c1.get("AZ"));
        assertEquals(null, c1.get("CZ"));
        assertEquals(2, c1.size());

        cachingService.resetCaches();

        assertEquals(null, c1.get("AZ"));
        assertEquals(0, c1.size());
       
        c1 = null;
    }
View Full Code Here

     * Test method for {@link org.dspace.services.caching.CachingServiceImpl#destroyCache(java.lang.String)}.
     */
    @Test
    public void testDestroyCache() {
        // destroy existing cache
        Cache cache = cachingService.getCache("org.dspace.caching.MemOnly", null);
        assertNotNull(cache);

        cachingService.destroyCache(cache.getName());

        Cache c2 = cachingService.getCache("org.dspace.caching.MemOnly", null);
        assertNotNull(c2);
        assertNotSame(cache, c2);

        // ok to destroy non-existent caches
        cachingService.destroyCache("XXXXXXXXXXXX");

        // destroy new cache
        Cache ca = cachingService.getCache("org.dspace.aztest", null);
        assertNotNull(ca);

        cachingService.destroyCache(ca.getName());

        Cache cb = cachingService.getCache("org.dspace.aztest", null);
        assertNotNull(cb);
        assertNotSame(ca, cb);
       
        //trash the references
        cache = c2 = ca = cb = null;
View Full Code Here

TOP

Related Classes of org.dspace.services.model.Cache

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.