Skip to content

Instantly share code, notes, and snippets.

@MotiurRahman
Last active August 6, 2017 12:37
Show Gist options
  • Save MotiurRahman/10109159 to your computer and use it in GitHub Desktop.
Save MotiurRahman/10109159 to your computer and use it in GitHub Desktop.
How to delete cache file in webView
/*When we load any website site in webView it generate some cache file also in the app cacheDirectory we
can delete this easily, here is the sample code*/
var win = Ti.UI.createWindow({
layout : 'vertical',
exitOnClose : true
});
var delBtn = Ti.UI.createButton({
top : 10,
left : 0,
right : 0,
height : '50',
title : '2) Delete Cache'
});
delBtn.addEventListener('click', function(e) {
var webViewCacheDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory, "webviewCache");
Ti.API.info('CACHE DIR');
Ti.API.info("cacheDiroctory=" + Ti.Filesystem.applicationCacheDirectory);
Ti.API.info('CONTENTS');
Ti.API.info(webViewCacheDir.getDirectoryListing());
Ti.API.info('Array length before: ' + webViewCacheDir.getDirectoryListing().length);
webViewCacheDir.deleteDirectory(true);
Ti.API.info('Array length after: ' + webViewCacheDir.getDirectoryListing().length);
});
var reloadBtn = Ti.UI.createButton({
top : 10,
left : 0,
right : 0,
height : '50',
title : '1) Reload'
});
reloadBtn.addEventListener('click', function(e) {
webview.reload();
});
var deallocateBtn = Ti.UI.createButton({
top : 10,
left : 0,
right : 0,
height : '50',
title : '3) Deallocate'
});
deallocateBtn.addEventListener('click', function(e) {
Ti.API.info('Deallocating WebView ');
win.close();
win.remove(webview);
webview = null;
Ti.API.info('WebView: ' + webview);
});
var webview = Ti.UI.createWebView({
top : 0,
height : '200dp',
left : 0,
right : 0,
url : 'http://www.appcelerator.com/'
});
win.add(webview);
win.add(reloadBtn);
win.add(delBtn);
win.add(deallocateBtn);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment