0

I am working on an app with Appcelerator. Appcelerator uses nearly the same kind of require.js like node.js does.

Now I want to implement a feature that logges out the current user and does not leave any trace. The most simple way would be to restart the app, but Appcelerator and especially Apple does not support this.

So i have to open the login window and clean all the data that leaves a trace to the old user.

The easiest way would be to dereference one of the main nodes in the require chain leaving all the data dereferenced and garbage collected. I know there is a way (as mentioned here) to do that in node:

/**
* Removes a module from the cache
*/
function purgeCache(moduleName) {
    // Traverse the cache looking for the files
    // loaded by the specified module name
    searchCache(moduleName, function (mod) {
        delete require.cache[mod.id];
    });

    // Remove cached paths to the module.
    // Thanks to @bentael for pointing this out.
    Object.keys(module.constructor._pathCache).forEach(function(cacheKey) {
        if (cacheKey.indexOf(moduleName)>0) {
            delete module.constructor._pathCache[cacheKey];
        }
   });
};

/**
* Traverses the cache to search for all the cached
* files of the specified module name
*/
function searchCache(moduleName, callback) {
    // Resolve the module identified by the specified name
    var mod = require.resolve(moduleName);

    // Check if the module has been resolved and found within
    // the cache
    if (mod && ((mod = require.cache[mod]) !== undefined)) {
        // Recursively go over the results
        (function traverse(mod) {
            // Go over each of the module's children and
            // traverse them
            mod.children.forEach(function (child) {
                traverse(child);
            });

            // Call the specified callback providing the
            // found cached module
            callback(mod);
        }(mod));
    }
};

So I tried to read out the require-cache in Appcelerator with:console.log(require, "-" ,require.cache); with an output like: <KrollCallback: 0x79f6fe50> - <null>

So now my questions:

  1. Is there a way to reach the require-cache in Appcelerator?
  2. Do you know a way to clean up a big Appcelerator-App?

Since it is possible to wirte native Modules for Appcelerator:

  1. Do you know a way to clean up a big Android App?
  2. Do you know a way to clean up a big iOS App?

Thank you very much

Community
  • 1
  • 1
J Polack
  • 118
  • 1
  • 1
  • 5
  • 1
    What data do you have to get rid of? I store all of my user info in a database and simply delete the database when the user logs out (they have the option to back up their data to our servers beforehand). You can clear your DB with 2 lines of code: `var db = Ti.Database.open('DatabaseName'); db.execute('DELETE FROM tableName');` This will delete the data out of your DB, but keep your tables and column intact (it's like TRUNCATE). – Nathan Follmer Jun 29 '16 at 15:40
  • It is a lot of passing data, like formdata or sessiondata. So the data needs to be high flexible and quick accessible. Because of that I am not sure if storing all the RAM data into a database would be a good option. – J Polack Jun 30 '16 at 07:49
  • How are you storing the user info in the app? Using Ti.App.Properties? Database? – Carlos Zinato Jul 01 '16 at 14:29

0 Answers0