titanium-cache provides caching for Appcelerator’s Titanium Mobile applications.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.textile
cache.js
cache_tests.js

README.textile

titanium-cache

titanium-cache provides caching for Appcelerator’s Titanium Mobile applications.

How it works

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.

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:

Ti.include('cache.js');

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

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);

3. Delete item from cache

Ti.App.Cache.del('my_data');

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.

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.

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.

If you have any other questions, please contact me through Twitter or e-mail.

License

titanium-cache is licensed under Apache Public License (Version 2). See LICENSE for more details.

Developed by Guilherme Chapiewski with contributions from Robb Shecter.