Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.octo.android.robospice.persistence;
 
 
An entity responsible for loading/saving data from/to cache. It implements a Chain of Responsability pattern, delegating loading and saving operations to ObjectPersister or ObjectPersisterFactory elements. The chain of responsibility is ordered. This means that the order used to register elements matters. All elements in the chain of responsibility are questioned in order. The first element that can handle a given class for persistence will be used to persist data of this class.

Author(s):
sni
public class CacheManager implements ICacheManager {

    
The Chain of Responsability list of all ObjectPersisterFactory.
    private CollectionObjectPersisterFactory > factoryList = new ArrayListObjectPersisterFactory >();

    
    public void addObjectPersisterFactoryObjectPersisterFactory factory ) {
        .addfactory );
    }

    
    public void removeObjectPersisterFactoryObjectPersisterFactory factory ) {
        .removefactory );
    }

    
    public < T > T loadDataFromCacheClass< T > clazzObject cacheKeylong maxTimeInCacheBeforeExpiry ) throws CacheLoadingException {
        return getClassCacheManagerclazz ).loadDataFromCachecacheKeymaxTimeInCacheBeforeExpiry );
    }
    @SuppressWarnings("unchecked")
    
    public < T > T saveDataToCacheAndReturnData( T dataObject cacheKey ) throws CacheSavingException {
        ObjectPersister< T > classCacheManager = (ObjectPersister< T >) getClassCacheManagerdata.getClass() );
        return classCacheManager.saveDataToCacheAndReturnDatadatacacheKey );
    }

    
    public boolean removeDataFromCacheClass< ? > clazzObject cacheKey ) {
        return getClassCacheManagerclazz ).removeDataFromCachecacheKey );
    }

    
    public void removeAllDataFromCacheClass< ? > clazz ) {
        getClassCacheManagerclazz ).removeAllDataFromCache();
    }

    
    public void removeAllDataFromCache() {
        for ( ObjectPersisterFactory factory : this. ) {
            factory.removeAllDataFromCache();
        }
    }

    
    protected < T > ObjectPersister< T > getClassCacheManagerClass< T > clazz ) {
        for ( ObjectPersisterFactory factory : this. ) {
            if ( factory.canHandleClassclazz ) ) {
                return factory.createClassCacheManagerclazz );
            }
        }
        throw new IllegalArgumentException"Class " + clazz.getName() + " is not handled by any registered factoryList" );
    }
New to GrepCode? Check out our FAQ X