Last active
August 6, 2017 12:37
-
-
Save MotiurRahman/10109159 to your computer and use it in GitHub Desktop.
How to delete cache file in webView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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