titanium-cache provides caching for Appcelerator’s Titanium Mobile applications.
Titanium Mobile translates your hard won JavaScript skills into native applications that perform and look just like they were written in Objective-C (iPhone and iPad) or Java (Android).
Mobile applications usually perform requests over the Internet to get data from APIs, and they can get very slow depending on the number of API calls you need to make.
titanium-cache provides caching capabilities for Titanium Mobile applications using SQLite local storage, so you can improve the performance of your mobile applications.
Just copy the cache.js to your project and include it (only once) from your app.js file using:
Ti.include('cache.js');
After that, the caching functions will be available under Ti.App.Cache.*, just like Titanium native functions.
var cached_obj = Ti.App.Cache.get('my_data');
You can cache strings or JavaScript native objects only. Images caching is not supported at this moment.
// if you do not specify, the default cache time is 5 minutes var my_javascript_object = { property: 'value' }; Ti.App.Cache.put('my_data', my_javascript_object);
// cache another object (a xml document) for 1 hour // (you can specify different cache expiration times then 5 minutes) Ti.App.Cache.put('another_data', xml_document, 3600);
Ti.App.Cache.del('my_data');
If you need to disable cache (useful while you are developing the application), just go to cache.js file and change the DISABLE variable value to true.
titanium-cache tests are located in the cache_tests.js file.
These tests are written in Jasmine using titanium-jasmine as the test runner.
For more info on how to run these tests in your application, please refer to titanium-jasmine documentation on GitHub.
If you want to see how I use titanium-cache on a real production project, please take a look at Yahoo! Meme’s source code on GitHub.
If you have any other questions, please contact me through Twitter or e-mail.
titanium-cache is licensed under Apache Public License (Version 2). See LICENSE for more details.
Developed by Guilherme Chapiewski with contributions from Robb Shecter.