<commit_before>cordova cache
=============

Javascript class for cordova app caching using file system api.

### usage - with cryption
```js
try{
    SI.cordovaCache('co.uk.sites-ignite.cache', function(cache, crypto){
        console.log(crypto);
        var DoSuccess = function(){
                console.log(cache.list());
                var MyCrypt = cache.container('MyCrypt', true); // true means to encrypt the data , defaults to false
                MyCrypt.put( JSON.stringify( { secretKey : 'acbef12345' } ) );
                MyCrypt.save(function(allC){
                    console.log('All data from cache');
                    console.log(allC);
                });
                MyCrypt.get();  // return the value held within the container
                console.log(MyCrypt.details());
                console.log(MyCrypt.details().crypt);
            },
            DoFailure = function(){
                // inform user of wrong password -> try again ?
                crypto.init('WrongPassword', DoSuccess, DoFailure);
            };

        if(crypto.isset()){
            // crypto has been set with a password , now we need to verify
            crypto.init('password', DoSuccess, DoFailure);
        }else{
            // crypto setup is required, obv you would have a user form & view with PWD vs PWD etc
            crypto.setPwd('password', DoSuccess);
        }
    });
}catch(e){
    console.log(e.message);
}
```

### Usage - no cryption
```js
// initiate the class which will create your caching file
try {
    SI.cordovaCache('io.cordova.cordovaCache', function(cache){
        console.log(cache);
        console.log(cache.list()); // array of created container

        var myContainer = cache.container('containerName');
        myContainer.get(); // return the value held within the container
        myContainer.put('Hello world'); // add to the container , overwrites previous data
        myContainer.save(); // save the data to the cache file, callback option param
        myContainer.save(function(content){
            console.log(content);
            // all content from the cache file in JSON string format
        });
        myContainer.details(); // object { created & updated } times
        
        var myOtherContainer = cache.container('myOtherContainer');
        var another = cache.container('another');
    });
} catch(e){
    console.log(e.message);
}
```

### window.SI , jQuery, angular , requirejs
* .cordovaCache : 2 params { 1 - string(id of your cordova app) , 2 - callback with cache and crypto:(optional) objects } throws exceptions on errors

```js
    SI.cordovaCache('io.hellocordova.cache', function(cache){// etc });
```
```js
    $.cordovaCache('io.hellocordova.cache', function(cache, crypto){// etc});
```
```js
    // angular factory
    angular.module('app', ['SI.cordova'])
    .controller('home', function($scope, cordovaCache){
        cordovaCache('io.hellocordova.cache', function(cache){// etc });
    });
```
```js
    requirejs(['cordovaCache'], function(cordovaCache){
        cordovaCache('io.hellocordova.cache', function(cache, crypto){// etc });
    });
```
### cache methods
* .list : 0 params , returns array of container available
* .container : 1 param { 1 - string } throws exception if not a string
* .rmAll    : 1 param:optional { 1-function , calls when complete }<commit_msg>Edit readme<commit_after>cordova cache
=============

Javascript class for cordova app caching using file system api.

### usage - with cryption
```js
try{
    SI.cordovaCache('co.uk.sites-ignite.cache', function(cache, crypto){
        console.log(crypto);
        var DoSuccess = function(){
                console.log(cache.list());
                var MyCrypt = cache.container('MyCrypt', true); // true means to encrypt the data , defaults to false
                MyCrypt.put( JSON.stringify( { secretKey : 'acbef12345' } ) );
                MyCrypt.save(function(allC){
                    console.log('All data from cache');
                    console.log(allC);
                });
                MyCrypt.get();  // return the value held within the container
                console.log(MyCrypt.details());
                console.log(MyCrypt.details().crypt);
            },
            DoFailure = function(){
                // inform user of wrong password -> try again ?
                crypto.init('WrongPassword', DoSuccess, DoFailure);
            };

        if(crypto.isset()){
            // crypto has been set with a password , now we need to verify
            crypto.init('password', DoSuccess, DoFailure);
        }else{
            // crypto setup is required, obv you would have a user form & view with PWD vs PWD etc
            crypto.setPwd('password', DoSuccess);
        }
    });
}catch(e){
    console.log(e.message);
}
```

### Usage - no cryption
```js
// initiate the class which will create your caching file
try {
    SI.cordovaCache('io.cordova.cordovaCache', function(cache){
        console.log(cache);
        console.log(cache.list()); // array of created container

        var myContainer = cache.container('containerName');
        myContainer.get(); // return the value held within the container
        myContainer.put('Hello world'); // add to the container , overwrites previous data
        myContainer.save(); // save the data to the cache file, callback option param
        myContainer.save(function(content){
            console.log(content);
            // all content from the cache file in JSON string format
        });
        myContainer.details(); // object { created & updated } times
        
        var myOtherContainer = cache.container('myOtherContainer');
        var another = cache.container('another');
    });
} catch(e){
    console.log(e.message);
}
```

### window.SI , jQuery, angular , requirejs
* .cordovaCache : 2 params { 1 - string(id of your cordova app) , 2 - callback with cache and crypto:(optional) objects } throws exceptions on errors

```js
    SI.cordovaCache('io.hellocordova.cache', function(cache){// etc });
```
```js
    $.cordovaCache('io.hellocordova.cache', function(cache, crypto){// etc});
```
```js
    // angular factory
    angular.module('app', ['SI.cordova'])
    .controller('home', function($scope, cordovaCache){
        cordovaCache('io.hellocordova.cache', function(cache){// etc });
    });
```
```js
    requirejs(['cordovaCache'], function(cordovaCache){
        cordovaCache('io.hellocordova.cache', function(cache, crypto){// etc });
    });
```
### cache methods
* .list : 0 params , returns array of container available
* .container : 2 param { 1 - string, 2 - boolena (optional) } throws exception if $1 is not a string or $2 is given but isnt a boolena
* .rmAll    : 1 param:optional { 1-function , calls when complete }
{'fraction_non_alphanumeric': 0.13620386643233742, 'fraction_numerical': 0.00424721734036321, 'mean_word_length': 2.457721518987342, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '273501', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1788, 'n_words': 544}