当前位置: 首页>>代码示例>>Java>>正文


Java DiskBasedCache类代码示例

本文整理汇总了Java中com.android.volley.toolbox.DiskBasedCache的典型用法代码示例。如果您正苦于以下问题:Java DiskBasedCache类的具体用法?Java DiskBasedCache怎么用?Java DiskBasedCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DiskBasedCache类属于com.android.volley.toolbox包,在下文中一共展示了DiskBasedCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRequestQueue

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {

        // Instantiate the cache
        Cache cache = new DiskBasedCache(mContext.getCacheDir(), 1024 * 1024); // 1MB cap
        // Set up the network to use HttpURLConnection as the HTTP client.
        Network network = new BasicNetwork(new HurlStack());
        // Instantiate the RequestQueue with the cache and network.
        mRequestQueue = new RequestQueue(cache, network);
        // Start the queue
        mRequestQueue.start();

        // getApplicationContext() is key, it keeps you from leaking the
        // Activity or BroadcastReceiver if someone passes one in.
        //mRequestQueue = Volley.newRequestQueue(mContext.getApplicationContext());
    }
    return mRequestQueue;
}
 
开发者ID:delizondo,项目名称:CursoAndroid,代码行数:19,代码来源:ApiClient.java

示例2: newVolleyRequestQueueForTest

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
private RequestQueue newVolleyRequestQueueForTest(final Context context) {
    File cacheDir = new File(context.getCacheDir(), "cache/volley");
    Network network = new BasicNetwork(new HurlStack());
    ResponseDelivery responseDelivery = new ExecutorDelivery(Executors.newSingleThreadExecutor());
    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network, 4, responseDelivery);
    queue.start();

    return queue;
}
 
开发者ID:Q115,项目名称:Goalie_Android,代码行数:10,代码来源:BaseTest.java

示例3: newRequestQueue

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
/**
 * Creates a new Request Queue which caches to the external storage directory
 * @param context
 * @return
 */
private static RequestQueue newRequestQueue(Context context) {
    // define cache folder
    File rootCache = context.getExternalCacheDir();
    if (rootCache == null) {
        Log.w(TAG, "Can't find External Cache Dir, "
                + "switching to application specific cache directory");
        rootCache = context.getCacheDir();
    }

    File cacheDir = new File(rootCache, DEFAULT_CACHE_DIR);
    cacheDir.mkdirs();

    HttpStack stack = new HurlStack();
    Network network = new BasicNetwork(stack);
    DiskBasedCache diskBasedCache = new DiskBasedCache(cacheDir, DEFAULT_DISK_USAGE_BYTES);
    RequestQueue queue = new RequestQueue(diskBasedCache, network);
    queue.start();

    return queue;
}
 
开发者ID:bilbo7833,项目名称:shutterstock-image-browser,代码行数:26,代码来源:VolleySingleton.java

示例4: newRequestQueue

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
/**
 * volley's default implementation uses internal cache only so we've implemented our, allowing
 * external cache usage.
 */
@NonNull
private static RequestQueue newRequestQueue(@NonNull final Context context,
        @Nullable HttpStack stack) {

    final VolleyHelperFactory.IVolleyHelper helper = VolleyHelperFactory.newHelper();
    final File cacheDir = helper.getBestCacheDir(context);

    if (stack == null) {
        stack = helper.createHttpStack(context);
    }

    final Network network = new BasicNetwork(stack);
    final RequestQueue queue = new RequestQueue(
            new DiskBasedCache(cacheDir, ApplicationConfig.CACHE_DISK_USAGE_BYTES), network, 1);
    queue.start();
    return queue;
}
 
开发者ID:lemberg,项目名称:android-project-template,代码行数:22,代码来源:DrupalModel.java

示例5: newRequestQueue

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
/**
 * volley's default implementation uses internal cache only so we've implemented our, allowing
 * external cache usage.
 */
private static RequestQueue newRequestQueue(@NonNull final Context context,
        @Nullable HttpStack stack) {

    final VolleyHelperFactory.IVolleyHelper helper = VolleyHelperFactory.newHelper();
    final File cacheDir = helper.getBestCacheDir(context);

    if (stack == null) {
        stack = helper.createHttpStack(context);
    }

    final Network network = new BasicNetwork(stack);
    final RequestQueue queue = new RequestQueue(
            new DiskBasedCache(cacheDir, ApplicationConfig.CACHE_DISK_USAGE_BYTES), network, 1);
    queue.start();
    return queue;
}
 
开发者ID:lemberg,项目名称:android-project-template,代码行数:21,代码来源:Model.java

示例6: newRequestQueue

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
private static RequestQueue newRequestQueue(Context context) {

        // On HC+ use HurlStack which is based on HttpURLConnection. Otherwise fall back on
        // AndroidHttpClient (based on Apache DefaultHttpClient) which should no longer be used
        // on newer platform versions where HttpURLConnection is simply better.
        Network network = new BasicNetwork(
                UIUtils.hasHoneycomb() ?
                        new HurlStack() :
                        new HttpClientStack(AndroidHttpClient.newInstance(
                                NetUtils.getUserAgent(context))));

        Cache cache = new DiskBasedCache(getDiskCacheDir(context, CACHE_DIR));
        RequestQueue queue = new RequestQueue(cache, network);
        queue.start();
        return queue;
    }
 
开发者ID:BitCypher2014,项目名称:Wardrobe_app,代码行数:17,代码来源:ImageLoader.java

示例7: newRequestQueue

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
private RequestQueue newRequestQueue(Context context) {
    // define cache folder
    File rootCache = context.getExternalCacheDir();
    if (rootCache == null) {
        rootCache = context.getCacheDir();
    }

    File cacheDir = new File(rootCache, DEFAULT_CACHE_DIR);
    cacheDir.mkdirs();

    HttpStack stack = new HurlStack();
    Network network = new BasicNetwork(stack);
    DiskBasedCache diskBasedCache = new DiskBasedCache(cacheDir, DEFAULT_DISK_USAGE_BYTES);
    RequestQueue queue = new RequestQueue(diskBasedCache, network);
    queue.start();

    return queue;
}
 
开发者ID:googlesamples,项目名称:io2014-codelabs,代码行数:19,代码来源:CloudBackendFragment.java

示例8: onCreate

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
@Override
public void onCreate() {
	super.onCreate();

	PREFS = new PreferenceWrapper( this );
	PREFS.listen();

	DISK_CACHE = new DiskBasedCache( getExternalCacheDir(), DISK_CACHE_SIZE );
	MEMORY_CACHE = new MangaMemoryCache();

	// Use the same disk cache for main and background download queues
	REQUEST_QUEUE = new RequestQueue( DISK_CACHE, new BasicNetwork( new HurlStack() ));
	REQUEST_QUEUE.start();

	// Use a custom in-memory LruCache for the loader
	IMAGE_LOADER = new ImageLoader( REQUEST_QUEUE, MEMORY_CACHE );

	// Setup databases
	Library.setDB( LibraryDatabaseHelper.getInstance( this ).getWritableDatabase() );
	Collection.setDB( CollectionDatabaseHelper.getInstance( this ).getWritableDatabase() );

	MangaUpdateReceiver.startUpdateCycle( this );
}
 
开发者ID:Alexander-Prime,项目名称:MangaJunkie-Android,代码行数:24,代码来源:App.java

示例9: build

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
public VolleyBallConfig build() {
    if (mInstance.mHttpStack == null) {
        mInstance.mHttpStack = ConfigUtils.getDefaultHttpStack(mInstance.mContext);
    }

    if (mInstance.mNetwork == null) {
        mInstance.mNetwork = ConfigUtils.getDefaultNetwork(mInstance.mHttpStack);
    }

    if (mInstance.mCache == null) {
        File cacheDir = new File(mInstance.mContext.getCacheDir(), DEFAULT_CACHE_DIR);
        mInstance.mCache = new DiskBasedCache(cacheDir);
    }

    return mInstance;
}
 
开发者ID:lukaspili,项目名称:Volley-Ball,代码行数:17,代码来源:VolleyBallConfig.java

示例10: QMusicRequestManager

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
/**
 * Use a custom L2 cache,support LRU
 * 
 * @param context
 * @param uniqueName
 * @param diskCacheSize
 * @param memCacheSize
 * @param compressFormat
 * @param quality
 * @param type
 */
private QMusicRequestManager(final Context context, final int diskCacheSize, final int memCacheSize) {
	// ============L2 Cache=============
	HttpStack stack = getHttpStack(false);
	Network network = new BasicNetwork(stack);
	if (L2CacheType == 0) {
		// TODO: this L2 cache implement ignores the HTTP cache headers
		mCacheL2 = new VolleyL2DiskLruCache(new File(context.getCacheDir(), "L2-Cache"), diskCacheSize);
	} else {
		// The build-in L2 cache has no LRU
		mCacheL2 = new DiskBasedCache(new File(context.getCacheDir(), "L2-Cache"), diskCacheSize);
	}
	mRequestQueue = new RequestQueue(mCacheL2, network);
	mRequestQueue.start();
	// ============L1 Cache=============
	if (L1CacheType == 0) {
		mCacheL1 = new VolleyL1MemoryLruImageCache(memCacheSize);
	} else {
		mCacheL1 = new VolleyL1DiskLruImageCache(context, "L1-Cache", diskCacheSize, CompressFormat.JPEG, 80);
	}
	mImageLoader = new ImageLoader(mRequestQueue, mCacheL1);
}
 
开发者ID:qianweicheng,项目名称:Qmusic,代码行数:33,代码来源:QMusicRequestManager.java

示例11: cache

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
/**
 * Initialize {@link SuperVolley} with a disk base cache
 *
 * @param context      Application context to get access to the applications cache directory
 * @param cacheDirName The name of {@link SuperVolley}'s cache directory
 */
public Builder cache(Context context, String cacheDirName) {
    final File cacheDirPath = context.getCacheDir();
    final File cacheDir = new File(cacheDirPath, cacheDirName);
    cache(new DiskBasedCache(cacheDir));
    return this;
}
 
开发者ID:octaware,项目名称:super-volley,代码行数:13,代码来源:SuperVolley.java

示例12: start

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
/**
 * Inicia uma instancia da lib PlainRequest
 * utilizando cache do volley
 *
 * @param app
 * @param sizeCache // tamanho do cache em MB
 */
public void start(Application app, int sizeCache) {
    if(context == null) {
        context = app.getApplicationContext();
        // Cache
        Cache cache = new DiskBasedCache(app.getCacheDir(), (1024 * 1024) * sizeCache);
        Network network = new BasicNetwork(new HurlStack());
        queue = new RequestQueue(cache, network); // Criação do RequestQueue
    }
}
 
开发者ID:giovanimoura,项目名称:plainrequest,代码行数:17,代码来源:PlainRequestQueue.java

示例13: HTTPAlbumImageProvider

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
private HTTPAlbumImageProvider(Context context) {
    // Don't use MALPRequestQueue because we do not need to limit the load on the local server
    Network network = new BasicNetwork(new HurlStack());
    // 10MB disk cache
    Cache cache = new DiskBasedCache(context.getCacheDir(), 1024 * 1024 * 10);

    mRequestQueue = new RequestQueue(cache, network);
    mRequestQueue.start();
}
 
开发者ID:gateship-one,项目名称:malp,代码行数:10,代码来源:HTTPAlbumImageProvider.java

示例14: getInstance

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
public synchronized static MALPRequestQueue getInstance(Context context) {
    if ( null == mInstance ) {
        Network network = new BasicNetwork(new HurlStack());
        // 10MB disk cache
        Cache cache = new DiskBasedCache(context.getCacheDir(), 1024 * 1024 * 10);

        mInstance = new MALPRequestQueue(cache,network);
        mInstance.start();
    }
    return mInstance;
}
 
开发者ID:gateship-one,项目名称:malp,代码行数:12,代码来源:MALPRequestQueue.java

示例15: initRequestQueue

import com.android.volley.toolbox.DiskBasedCache; //导入依赖的package包/类
private void initRequestQueue(@NonNull Context context) {
    if (mRequestQueue != null) {
        return;
    }
    Network network = new BasicNetwork(new OkHttpStack());
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
    mRequestQueue = new RequestQueue(new DiskBasedCache(cacheDir), network, DEFAULT_NETWORK_THREAD_POOL_SIZE);
    mRequestQueue.start();
}
 
开发者ID:hacket,项目名称:NetRequest,代码行数:10,代码来源:VolleyManagerNew.java


注:本文中的com.android.volley.toolbox.DiskBasedCache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。