titanium-cache provides caching for Appcelerator’s Titanium Mobile applications.
How it works
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.
How to use in your projects
Just copy the cache.js to your project and include it (only once) from your app.js file using:
After that, the caching functions will be available under Ti.App.Cache.*, just like Titanium native functions.
1. Get item from cache
var cached_obj = Ti.App.Cache.get('my_data');
2. Add item to cache
// 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);
3. Delete item from cache
4. Disabling cache for development
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.
How to run the tests
titanium-cache tests are located in the cache_tests.js file.
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.
titanium-cache is licensed under Apache Public License (Version 2). See LICENSE for more details.