titanium-cache
titanium-cache copied to clipboard
titanium-cache provides caching for Appcelerator’s Titanium Mobile applications.
h1. titanium-cache
titanium-cache provides caching for "Appcelerator's Titanium Mobile":http://www.appcelerator.com/products/titanium-mobile-application-development/ applications.
h2. How it works
"Titanium Mobile":http://www.appcelerator.com/products/titanium-mobile-application-development/ 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":http://www.appcelerator.com/products/titanium-mobile-application-development/ applications using SQLite local storage, so you can improve the performance of your mobile applications.
h2. How to use in your projects
Just copy the "cache.js":http://github.com/guilhermechapiewski/titanium-cache/blob/master/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.
h3. 1. Get item from cache
var cached_obj = Ti.App.Cache.get('my_data');
h3. 2. Add item to cache
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);
h3. 3. Delete item from cache
Ti.App.Cache.del('my_data');
h3. 4. Disabling cache for development
If you need to disable cache (useful while you are developing the application), just go to "cache.js":http://github.com/guilhermechapiewski/titanium-cache/blob/master/cache.js file and change the DISABLE variable value to true.
h2. How to run the tests
titanium-cache tests are located in the "cache_tests.js":http://github.com/guilhermechapiewski/titanium-cache/blob/master/cache_tests.js file.
These tests are written in "Jasmine":http://pivotal.github.com/jasmine/ using "titanium-jasmine":http://github.com/guilhermechapiewski/titanium-jasmine#readme as the test runner.
For more info on how to run these tests in your application, please refer to "titanium-jasmine documentation on GitHub":http://github.com/guilhermechapiewski/titanium-jasmine#readme.
h2. More info
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":http://github.com/acarlos1000/MemeiPhone.
If you have any other questions, please contact me through "Twitter":http://twitter.com/gchapiewski or "e-mail":http://guilherme.it.
h2. License
titanium-cache is licensed under Apache Public License (Version 2). See "LICENSE":http://github.com/guilhermechapiewski/titanium-cache/blob/master/LICENSE for more details.
Developed by "Guilherme Chapiewski":http://guilherme.it with contributions from "Robb Shecter":http://www.weblaws.org/robb/.