diff --git a/ionic/components/app/test/storage/index.ts b/ionic/components/app/test/storage/index.ts index d4a2eb9d1e..76c530aa1b 100644 --- a/ionic/components/app/test/storage/index.ts +++ b/ionic/components/app/test/storage/index.ts @@ -1,7 +1,7 @@ import {Component} from 'angular2/angular2'; import {Control, ControlGroup} from 'angular2/forms'; -import {App, Http, Storage, LocalStorage, SQLStorage} from 'ionic/ionic'; +import {App, Http, Storage, LocalStorage, SqlStorage} from 'ionic/ionic'; let testUrl = 'https://ionic-api-tester.herokuapp.com/json'; let testUrl404 = 'https://ionic-api-tester.herokuapp.com/404'; @@ -13,7 +13,7 @@ let testUrl404 = 'https://ionic-api-tester.herokuapp.com/404'; class IonicApp { constructor() { this.local = new Storage(LocalStorage); - this.sql = new Storage(SQLStorage); + this.sql = new Storage(SqlStorage); } getLocal() { this.local.get('name').then(value => { diff --git a/ionic/storage/local-storage.ts b/ionic/storage/local-storage.ts index d61ef12f32..8051032914 100644 --- a/ionic/storage/local-storage.ts +++ b/ionic/storage/local-storage.ts @@ -1,6 +1,17 @@ -import {StorageStrategy} from './storage'; +import {StorageEngine} from './storage'; -export class LocalStorage extends StorageStrategy { + +/** + * The LocalStorage storage engine uses the browser's local storage system for + * storing key/value pairs. + * + * Note: LocalStorage should ONLY be used for temporary data that you can afford to lose. + * Given disk space constraints on a mobile device, local storage might be "cleaned up" + * by the operating system (iOS). + * + * For guaranteed, long-term storage, use the SqlStorage engine which stores data in a file. + */ +export class LocalStorage extends StorageEngine { constructor() { super(); } diff --git a/ionic/storage/sql.ts b/ionic/storage/sql.ts index 9b1b97f01d..080f74a377 100644 --- a/ionic/storage/sql.ts +++ b/ionic/storage/sql.ts @@ -1,10 +1,10 @@ -import {StorageStrategy} from './storage'; +import {StorageEngine} from './storage'; import * as util from 'ionic/util'; const DB_NAME = '__ionicstorage'; -export class SQLStorage extends StorageStrategy { +export class SqlStorage extends StorageEngine { static BACKUP_LOCAL = 2 static BACKUP_LIBRARY = 1 static BACKUP_DOCUMENTS = 0 @@ -14,7 +14,7 @@ export class SQLStorage extends StorageStrategy { let dbOptions = util.defaults({ name: DB_NAME, - backupFlag: SQLStorage.BACKUP_NONE, + backupFlag: SqlStorage.BACKUP_NONE, existingDatabase: false }, options); @@ -37,11 +37,11 @@ export class SQLStorage extends StorageStrategy { _getBackupLocation(dbFlag) { switch(dbFlag) { - case SQLStorage.BACKUP_LOCAL: + case SqlStorage.BACKUP_LOCAL: return 2; - case SQLStorage.BACKUP_LIBRARY: + case SqlStorage.BACKUP_LIBRARY: return 1; - case SQLStorage.BACKUP_DOCUMENTS: + case SqlStorage.BACKUP_DOCUMENTS: return 0; default: throw Error('Invalid backup flag: ' + dbFlag); diff --git a/ionic/storage/storage.ts b/ionic/storage/storage.ts index 9ba626a887..b7b011d785 100644 --- a/ionic/storage/storage.ts +++ b/ionic/storage/storage.ts @@ -1,9 +1,14 @@ /** * Storage is an easy way to store key/value pairs and other complicated - * data in a way that uses the best possible storage layer underneath. + * data in a way that uses a variety of storage engines underneath. + * + * For most cases, we recommend the SqlStorage system as it will store + * data in a file in the app's sandbox. LocalStorage should ONLY be used + * for temporary data as it may be "cleaned up" by the operation system + * during low disk space situations. */ export class Storage { - constructor(strategyCls: StorageStrategy) { + constructor(strategyCls: StorageEngine) { this._strategy = new strategyCls(); } get(key) { @@ -17,7 +22,7 @@ export class Storage { } } -export class StorageStrategy { +export class StorageEngine { get(key, value) { throw Error("Not implemented"); }