{"action":"created","issue":{"url":"https://api.github.com/repos/nostra13/Android-Universal-Image-Loader/issues/1148","repository_url":"https://api.github.com/repos/nostra13/Android-Universal-Image-Loader","labels_url":"https://api.github.com/repos/nostra13/Android-Universal-Image-Loader/issues/1148/labels{/name}","comments_url":"https://api.github.com/repos/nostra13/Android-Universal-Image-Loader/issues/1148/comments","events_url":"https://api.github.com/repos/nostra13/Android-Universal-Image-Loader/issues/1148/events","html_url":"https://github.com/nostra13/Android-Universal-Image-Loader/issues/1148","id":123157126,"number":1148,"title":"How to Implement Caching for custom ImageLoader?","user":{"login":"spremathilaka","id":2536705,"avatar_url":"https://avatars.githubusercontent.com/u/2536705?v=3","gravatar_id":"","url":"https://api.github.com/users/spremathilaka","html_url":"https://github.com/spremathilaka","followers_url":"https://api.github.com/users/spremathilaka/followers","following_url":"https://api.github.com/users/spremathilaka/following{/other_user}","gists_url":"https://api.github.com/users/spremathilaka/gists{/gist_id}","starred_url":"https://api.github.com/users/spremathilaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spremathilaka/subscriptions","organizations_url":"https://api.github.com/users/spremathilaka/orgs","repos_url":"https://api.github.com/users/spremathilaka/repos","events_url":"https://api.github.com/users/spremathilaka/events{/privacy}","received_events_url":"https://api.github.com/users/spremathilaka/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-20T12:21:37Z","updated_at":"2016-03-03T11:26:50Z","closed_at":null,"body":"I'm using \"Android-Universal-Image-Loader\" version \"1.9.5\", I've Implemented a custom Image Loader to read images from SQLITE Database, If the Image is not in DB it should download it from Web.\r\n\r\nHow can i implement cache for image loading from Sqlite Db?\r\n\r\n\r\n   ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);\r\n        config.threadPriority(Thread.NORM_PRIORITY - 2);\r\n        config.denyCacheImageMultipleSizesInMemory();\r\n        config.diskCacheFileNameGenerator(new Md5FileNameGenerator());\r\n        config.diskCacheSize(50 * 1024 * 1024); // 50 MiB\r\n        config.tasksProcessingOrder(QueueProcessingType.LIFO);\r\n        config.writeDebugLogs(); // Remove for release app\r\n        config.imageDownloader(new SqliteImageloader(context));\r\n        // Initialize ImageLoader with configuration.\r\n        ImageLoader.getInstance().init(config.build());\r\n\r\n\r\n\r\npublic class SqliteImageloader extends BaseImageDownloader {\r\n\r\n    private static final String SCHEME_DB = \"db\";\r\n    private static final String DB_URI_PREFIX = SCHEME_DB + \"://\";\r\n    private static SqliteImageloader instance = null;\r\n    private WidgetRepositoryHandler widgetRepository;\r\n    private DatabaseManager databaseManager;\r\n\r\n    public SqliteImageloader(Context context) {\r\n        super(context);\r\n        databaseManager = DatabaseManager.getInstance(context);\r\n        widgetRepository = databaseManager.getWidvgetRepository();\r\n    }\r\n\r\n\r\n    @Override\r\n    protected InputStream getStreamFromOtherSource(String imageUri, Object extra) throws\r\n            IOException {\r\n        if(!imageUri.contains(\"null\")) {\r\n            if (imageUri.startsWith(DB_URI_PREFIX)) {\r\n                String path = imageUri.substring(DB_URI_PREFIX.length());\r\n\r\n                // Your logic to retreive needed data from DB\r\n                byte[] imageData = widgetRepository.getImageRepository().getImageAsByteArray(path);\r\n                if (imageData != null) {\r\n                    return new ByteArrayInputStream(imageData);\r\n                }\r\n                imageUri = APIService.SERVER_BASE_URL+imageUri.replace(DB_URI_PREFIX,\"\");\r\n                return super.getStreamFromOtherSource(imageUri, extra);\r\n            } else {\r\n                imageUri = APIService.SERVER_BASE_URL+imageUri.replace(DB_URI_PREFIX,\"\");\r\n                return super.getStreamFromOtherSource(imageUri, extra);\r\n            }\r\n        }\r\n        return null;\r\n    }\r\n}"},"comment":{"url":"https://api.github.com/repos/nostra13/Android-Universal-Image-Loader/issues/comments/191717267","html_url":"https://github.com/nostra13/Android-Universal-Image-Loader/issues/1148#issuecomment-191717267","issue_url":"https://api.github.com/repos/nostra13/Android-Universal-Image-Loader/issues/1148","id":191717267,"user":{"login":"kalpeshsantoki07","id":1373708,"avatar_url":"https://avatars.githubusercontent.com/u/1373708?v=3","gravatar_id":"","url":"https://api.github.com/users/kalpeshsantoki07","html_url":"https://github.com/kalpeshsantoki07","followers_url":"https://api.github.com/users/kalpeshsantoki07/followers","following_url":"https://api.github.com/users/kalpeshsantoki07/following{/other_user}","gists_url":"https://api.github.com/users/kalpeshsantoki07/gists{/gist_id}","starred_url":"https://api.github.com/users/kalpeshsantoki07/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kalpeshsantoki07/subscriptions","organizations_url":"https://api.github.com/users/kalpeshsantoki07/orgs","repos_url":"https://api.github.com/users/kalpeshsantoki07/repos","events_url":"https://api.github.com/users/kalpeshsantoki07/events{/privacy}","received_events_url":"https://api.github.com/users/kalpeshsantoki07/received_events","type":"User","site_admin":false},"created_at":"2016-03-03T11:26:50Z","updated_at":"2016-03-03T11:26:50Z","body":"Thanks, That's really helpful to me. I have some queries as below, if you can answer me then it would be great for me:\r\n1) What data I will receive in 'Object extra' ?\r\n2) Actually I want more parameters as separate then imageUri in this custom loading logic, Is there any way to pass data while call displayImage then please let me know?\r\n\r\nAs now I am requesting as below:\r\nimageLoader.displayImage(imageUri, imageView, imageOptions);"}}