| 1 |
## Storage Usage |
| 2 |
Storage module is developed for client-side persistant storing of key & value pairs. |
| 3 |
|
| 4 |
```javascript |
| 5 |
|
| 6 |
// Initialize Storage. |
| 7 |
var Storage = require( 'udx.storage' ).create(); |
| 8 |
|
| 9 |
// Set some values. |
| 10 |
Storage.setItem( 'name', 'Andy' ); |
| 11 |
Storage.setItem( 'latitude', '34.4239' ); |
| 12 |
Storage.setItem( 'longitude', '-77.5584' ); |
| 13 |
|
| 14 |
// Later... |
| 15 |
console.log( 'Welcome', Storage.getItem( 'name' ), 'we have you located at', Storage.getItem( 'latitude' ), ', ', Storage.getItem( 'longitude' ) ); |
| 16 |
|
| 17 |
``` |
| 18 |
|
| 19 |
Storage attempts to save data into localStorage, if the browser supports it. Otherwise we fallback to Cookie storage. |
| 20 |
|
| 21 |
## Usage Notes |
| 22 |
* Root keys that start with __ will never be committed to storage. |
| 23 |
* There are four types of storage types available - "option", "site_meta", "transient" and "site_transient". |
| 24 |
|
| 25 |
## Settings Usage |
| 26 |
|
| 27 |
```php |
| 28 |
// Instantiate and load Settings. |
| 29 |
$settings = new Settings(array( |
| 30 |
"store" => "options", |
| 31 |
"key" => "settings_test", |
| 32 |
"format" => "object", |
| 33 |
"auto_commit" => true, |
| 34 |
"data" => array( 'initial data', 'blah' ) |
| 35 |
)); |
| 36 |
|
| 37 |
$settings->set( 'make', 'Chevy' ); |
| 38 |
$settings->set( 'model', 'Tahoe' ); |
| 39 |
|
| 40 |
$settings->set( 'features', array( |
| 41 |
'ac', |
| 42 |
'stuff' |
| 43 |
'dvd', |
| 44 |
'sunroof' |
| 45 |
)); |
| 46 |
|
| 47 |
$settings->set( 'options', array( |
| 48 |
"gps" => 'standard', |
| 49 |
"rims" => '24', |
| 50 |
"towing" => true, |
| 51 |
"onstar" => 'active' |
| 52 |
)); |
| 53 |
``` |
| 54 |
|
| 55 |
```php |
| 56 |
// Initialize Settings. |
| 57 |
$this->_settings = new Settings(array( |
| 58 |
"store" => "options", |
| 59 |
"key" => "ud:veneer", |
| 60 |
)); |
| 61 |
|
| 62 |
// ElasticSearch Service Settings. |
| 63 |
$this->set( 'documents', array( |
| 64 |
"host" => "localhost", |
| 65 |
"active" => true, |
| 66 |
"token" => "alsdkjflaksdjsadsdff", |
| 67 |
"port" => 9200 |
| 68 |
)); |
| 69 |
|
| 70 |
// Varnish Service Settings. |
| 71 |
$this->set( 'varnish', array( |
| 72 |
"host" => "localhost", |
| 73 |
"active" => false |
| 74 |
)); |
| 75 |
|
| 76 |
// CDN Service Settings. |
| 77 |
$this->set( 'cdn', array( |
| 78 |
"active" => true, |
| 79 |
"provider" => "gcs", |
| 80 |
"subdomain" => "media", |
| 81 |
"key" => "alsdkjflaksdjf" |
| 82 |
)); |
| 83 |
|
| 84 |
// Save Settings. |
| 85 |
$this->_settings->commit(); |
| 86 |
``` |
| 87 |
|
| 88 |
## License |
| 89 |
|
| 90 |
(The MIT License) |
| 91 |
|
| 92 |
Copyright (c) 2013 Usability Dynamics, Inc. <info@usabilitydynamics.com> |
| 93 |
|
| 94 |
Permission is hereby granted, free of charge, to any person obtaining |
| 95 |
a copy of this software and associated documentation files (the |
| 96 |
'Software'), to deal in the Software without restriction, including |
| 97 |
without limitation the rights to use, copy, modify, merge, publish, |
| 98 |
distribute, sublicense, and/or sell copies of the Software, and to |
| 99 |
permit persons to whom the Software is furnished to do so, subject to |
| 100 |
the following conditions: |
| 101 |
|
| 102 |
The above copyright notice and this permission notice shall be |
| 103 |
included in all copies or substantial portions of the Software. |
| 104 |
|
| 105 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
| 106 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 107 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 108 |
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 109 |
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 110 |
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 111 |
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 112 |
|