Android Open Source - octodroid Cache Control






From Project

Back to project page octodroid.

License

The source code is released under:

MIT License

If you think the Android project octodroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.rejasupotaro.octodroid.http;
//from w w w. ja v a2  s  . c om
import android.content.Context;

import java.io.File;

public class CacheControl {
    private File file;
    private int maxCacheSize;
    private int maxStale;

    public File getFile() {
        return file;
    }

    public int getMaxCacheSize() {
        return maxCacheSize;
    }

    public int getMaxStale() {
        return maxStale;
    }

    private CacheControl(Builder builder) {
        this.file = builder.file;
        this.maxCacheSize = builder.maxCacheSize;
        this.maxStale = builder.maxStale;
    }

    public static class Builder {
        private static final String DEFAULT_CACHE_FILE_NAME = "octodroid_response_cache";
        private static final int DEFAULT_MAX_CACHE_SIZE = 3 * 1024 * 1024; // 3MB
        private static final int DEFAULT_MAX_STALE = 28 * 24 * 60 * 60; // tolerate 4-weeks stale

        private File file;
        private int maxCacheSize = DEFAULT_MAX_CACHE_SIZE;
        private int maxStale = DEFAULT_MAX_STALE;

        public Builder file(Context context) {
            return file(context, DEFAULT_CACHE_FILE_NAME);
        }

        public Builder file(Context context, String fileName) {
            return file(new File(context.getCacheDir(), fileName));
        }

        public Builder file(File file) {
            this.file = file;
            return this;
        }

        public Builder maxCacheSize(int maxCacheSize) {
            this.maxCacheSize = maxCacheSize;
            return this;
        }

        public Builder maxStale(int maxStale) {
            this.maxStale = maxStale;
            return this;
        }

        public CacheControl build() {
            if (file == null) {
                throw new IllegalStateException("Cache file should not be null");
            }
            return new CacheControl(this);
        }
    }
}




Java Source Code List

com.example.octodroid.ApplicationTest.java
com.example.octodroid.MyApplication.java
com.example.octodroid.SessionPrefsSchema.java
com.example.octodroid.activities.LoginActivity.java
com.example.octodroid.activities.MainActivity.java
com.example.octodroid.activities.SearchResultActivity.java
com.example.octodroid.adapters.HottestRepositoryAdapter.java
com.example.octodroid.adapters.SearchResultAdapter.java
com.example.octodroid.views.DividerItemDecoration.java
com.example.octodroid.views.MoreLoadScrollListener.java
com.example.octodroid.views.ProfileView.java
com.example.octodroid.views.helpers.ProgressDialogHelper.java
com.example.octodroid.views.helpers.ToastHelper.java
com.example.octodroid.views.holders.ProgressViewHolder.java
com.example.octodroid.views.holders.RepositoryItemViewHolder.java
com.rejasupotaro.octodroid.ApplicationTest.java
com.rejasupotaro.octodroid.AuthenticationRequired.java
com.rejasupotaro.octodroid.ConnectivityObserver.java
com.rejasupotaro.octodroid.GitHubClient.java
com.rejasupotaro.octodroid.GitHub.java
com.rejasupotaro.octodroid.GsonProvider.java
com.rejasupotaro.octodroid.http.AbstractClient.java
com.rejasupotaro.octodroid.http.ApiClient.java
com.rejasupotaro.octodroid.http.CacheControl.java
com.rejasupotaro.octodroid.http.Header.java
com.rejasupotaro.octodroid.http.Link.java
com.rejasupotaro.octodroid.http.Method.java
com.rejasupotaro.octodroid.http.PaginationHeaderParserTest.java
com.rejasupotaro.octodroid.http.PaginationHeaderParser.java
com.rejasupotaro.octodroid.http.Pagination.java
com.rejasupotaro.octodroid.http.RequestCreator.java
com.rejasupotaro.octodroid.http.Response.java
com.rejasupotaro.octodroid.http.params.All.java
com.rejasupotaro.octodroid.http.params.Order.java
com.rejasupotaro.octodroid.http.params.Participating.java
com.rejasupotaro.octodroid.http.params.Sort.java
com.rejasupotaro.octodroid.http.params.Type.java
com.rejasupotaro.octodroid.models.Notification.java
com.rejasupotaro.octodroid.models.Plan.java
com.rejasupotaro.octodroid.models.Repository.java
com.rejasupotaro.octodroid.models.Resource.java
com.rejasupotaro.octodroid.models.SearchResult.java
com.rejasupotaro.octodroid.models.Subject.java
com.rejasupotaro.octodroid.models.User.java