You are here

Caching in %TEMP% folder?

14 posts / 0 new
Last post
vor0nwe
Offline
Last seen: 5 years 4 months ago
Joined: 2006-03-09 12:11
Caching in %TEMP% folder?

Would it be possible to include an option or something to the PortableFirefox launcher that would add a line to the user.js file in the profile directory?

Firefox is running fine from my USB key, but it's very sluggish when I have caching turned on (and it causes a lot of writes to the key, which apparently isn't very good for it). I've tried turning caching off, but that makes FF sluggish as well.

I then set the caching directory to the user's TEMP directory on the local hard drive, and then it works fine. However, this presents the following issues:
* The TEMP folder on several machines (or for different user accounts on the same machine) varies.
* The 'caching directory' preference doesn't support environment variables (like %TEMP%)

That's why I'd like to have the launcher append the line user_pref('browser.cache.disk.parent_directory', %TEMP%) with of course %TEMP% replaced by the corresponding environment value... And taking JS escaping into account, as well...

Ryan McCue
Ryan McCue's picture
Offline
Last seen: 14 years 6 months ago
Joined: 2006-01-06 21:27
NSIS

NSIS has the $TEMP constant
----
R McCue

"If you're not part of the solution, you're part of the precipitate."

vor0nwe
Offline
Last seen: 5 years 4 months ago
Joined: 2006-03-09 12:11
Thanks, but...

...I've never written anything in NSIS. Can it also do the Javascript escaping trick?
Is that .nsi-file the source code, that needs to be compiled somehow? (if so, how -- or rather, with what?)

--
"The Duke had a mind that ticked like a clock, and like a clock, it regularly went cuckoo."
-- Terry Pratchett, Wyrd Sisters

Thox
Offline
Last seen: 17 years 7 months ago
Joined: 2006-02-09 06:46
NSIS + Firefox

NSIS - Nullsoft Scriptable Install System

I'm not sure how you would get an NSIS variable into Firefox's settings though.

vor0nwe
Offline
Last seen: 5 years 4 months ago
Joined: 2006-03-09 12:11
NSIS

Thanks for the link, Thox.

Judging by this article writing the settings can be done, but not something I'd want to figure out. I'll stick to my JScript file.

--
"The Duke had a mind that ticked like a clock, and like a clock, it regularly went cuckoo."
-- Terry Pratchett, Wyrd Sisters

Ryan McCue
Ryan McCue's picture
Offline
Last seen: 14 years 6 months ago
Joined: 2006-01-06 21:27
I could

make it for you Smile
----
R McCue

"If you're not part of the solution, you're part of the precipitate."

John T. Haller
John T. Haller's picture
Offline
Last seen: 7 hours 26 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
Considering adding...

I've been considering adding this for a while. A couple caveats, though...

1. This introduces possible personal data onto the host PC, so it will have to be disabled by default
2. Disk cache doesn't actually speed up Firefox much during a single browsing session. It makes full use of the computer's RAM for caching. It's of more value to inter-session browsing... which, of course, it would be lost between.
3. It would need to be cleaned up after running Firefox, requiring PortableFirefox.exe to hang around consuming RAM until Firefox closes.
4. If the PC crashes, personal data will be left behind
5. If Firefox updates versions, PortableFirefox.exe will exit early, and any cache after that point will be left behind.

So, you can kinda see why I've been reluctant to build this in.

Sometimes, the impossible can become possible, if you're awesome!

vor0nwe
Offline
Last seen: 5 years 4 months ago
Joined: 2006-03-09 12:11
Fixed with JScript file

Re. 1, 3 and 5: Firefox can be set to clear the cache data itself. Of course, this still leaves a %TEMP%\Cache folder with three or four (NULL-filled) files of about 4K each.
Re. 2: It does seem to speed up Fx if you leave it running an entire day, and visit the same site(s) several times. It definitely does when you disable RAM caching. Smile

But I can't see a way around issue #4, either. I'm prepared to live with that, though...

But anyway, I've written a little PortableFirefox setup file in JScript. It needs to sit in the same folder as PortableFirefox.exe, and only needs to be run once on any PC (though it doesn't hurt).

I'll post it here, in case anyone is interested. It'll need to be adjusted to anyone's preferences; I've added several other absolute paths I found in my prefs.js, some of them customized for my USB key's folder structure.

SetupPFF.js

// Perform the main function of this script
main();
//
function main() {
    var idicPrefs = new ActiveXObject('Scripting.Dictionary');
    idicPrefs.CompareMode = 0; // binary compare
    var lobjFSO = new ActiveXObject('Scripting.FileSystemObject');
    var lobjShell = new ActiveXObject('WScript.Shell');
    //
    // Determine the current script's folder
    var lstrFolder = lobjFSO.GetParentFolderName(WScript.ScriptFullName);
    //
    // Read and backup the existing user.js file
    var lstrUserFileName = lobjFSO.BuildPath(lstrFolder, 'profile\\user.js');
    if(lobjFSO.FileExists(lstrUserFileName) && lobjFSO.GetFile(lstrUserFileName).Size > 0) {
        with(lobjFSO.OpenTextFile(lstrUserFileName)) {
            eval(ReadAll());
            Close();
        }
        with(lobjFSO.GetFile(lstrUserFileName)) {
            var lstrBackupExtension = '-' + createValidFilename(new Date().toLocaleString()) + '.bak';
            try {
                lobjFSO.DeleteFile(Name + lstrBackupExtension);
            }
            catch(lobjError) { };
            Name += lstrBackupExtension;
        }
    }
    //
    //
    // The purpose of this script: set the cache folder to use the local TEMP folder...
    idicPrefs('browser.cache.disk.parent_directory') = lobjShell.ExpandEnvironmentStrings('%TEMP%\\PFF');
    idicPrefs('browser.download.dir') = lobjShell.ExpandEnvironmentStrings('%HOMEDRIVE%%HOMEPATH%\\PFF');
    idicPrefs('conquery.Main.PlugsDir') = lobjFSO.BuildPath(lstrFolder, "profile\\searchplugins");
    idicPrefs('conquery.Main.PlugsDir2') = lobjShell.ExpandEnvironmentStrings('%ProgramFiles%\\Mozilla Firefox\\searchplugins');
    idicPrefs('local_install.base_extension_dir') = lobjFSO.BuildPath(lstrFolder, "XPIs");
    idicPrefs('local_install.default_CSS_editor') = lobjFSO.GetAbsolutePathName(lobjFSO.BuildPath(lstrFolder, "..\\Notepad++\\notepad++.exe"));
    idicPrefs('local_install.default_JS_editor') = lobjFSO.GetAbsolutePathName(lobjFSO.BuildPath(lstrFolder, "..\\Notepad++\\notepad++.exe"));
    idicPrefs('mozex.command.mailer') = lobjFSO.GetAbsolutePathName(lobjFSO.BuildPath(lstrFolder, "..\\PortableThunderbird\\PortableThunderbird.exe"));
    idicPrefs('network.protocol-handler.app.mailto') = lobjFSO.GetAbsolutePathName(lobjFSO.BuildPath(lstrFolder, "..\\PortableThunderbird\\PortableThunderbird.exe"));
    idicPrefs('dafi.viewsource.configPath') = lobjFSO.BuildPath(lstrFolder, "profile\\viewSource.xml");
    //
    //
    // Write out the changed user.js file
    var lstrUserPrefs = '';
    for(var lobjEnum = new Enumerator(idicPrefs); !lobjEnum.atEnd(); lobjEnum.moveNext()) {
        var lstrKey = lobjEnum.item();
        var lvarValue = idicPrefs(lstrKey);
        lstrUserPrefs += 'user_pref("' + lstrKey + '", ';
        switch(typeof(lvarValue)) {
            case 'string' : {
                lstrUserPrefs += '"' + escapeString(lvarValue) + '"';
                break;
            }
            default: {
                lstrUserPrefs += lvarValue;
            }
        }
        lstrUserPrefs += ');\r\n';
    }
    with(lobjFSO.OpenTextFile(lstrUserFileName, 2 /* ForWriting */, true)) {
        Write(lstrUserPrefs);
        Close();
    }
    //
    // Now run Portable Firefox
    if(confirm(lobjShell.ExpandEnvironmentStrings('Portable Firefox setup has successfully been adjusted to computer %COMPUTERNAME%.\n\nDo you want to launch PFF?'))) {
        lobjShell.Run(lobjFSO.BuildPath(lstrFolder, 'PortableFirefox.exe'), 1, false);
    }
    //
    // Clean up
    ldicPrefs = null;
    lobjFSO = null;
    lobjShell = null;
    return;
    //
    // This function will get called by the 'code' in user.js
    function user_pref(astrPref, avarValue) {
        idicPrefs(astrPref) = avarValue;
    }
    //
    // This returns a string fit to be used in JS code.
    function escapeString(astrExpression) {
        var lstrString = '' + astrExpression;
        return lstrString.replace(/\\/g, '\\\\').replace(/\r/g, '\\\r').replace(/\n/g, '\\\n').replace(/\"/g, '\\"');
    }
    //
    // This returns a string valid for use in a filename
    function createValidFilename(astrExpression) {
        var lstrValid = '' + astrExpression;
        lstrValid = lstrValid.replace(/\:/g, ';');
        lstrValid = lstrValid.replace(/\?/g, '¿');
        lstrValid = lstrValid.replace(/[\\\/\:\"\*\?\\|]/g, '_');
        return lstrValid;
    }
}

--
"The Duke had a mind that ticked like a clock, and like a clock, it regularly went cuckoo."
-- Terry Pratchett, Wyrd Sisters

Bruce Pascoe
Offline
Last seen: 12 years 2 months ago
Joined: 2006-01-15 16:14
?

Why would you disable RAM caching? I have Firefox's RAM cache set to 64 MB (the default, I think) and it doesn't really slow the machine down, even on a computer with a small amount of RAM (say 128 to 256 MB).

Edit: Note to self -- 64 MEGABYTES, Bruce, not kilobytes.

Bruce Pascoe
Offline
Last seen: 12 years 2 months ago
Joined: 2006-01-15 16:14
...

Also, your solution really doesn't solve problem #1 (leaving personal info on the guest computer) either. Deleting files by conventional means doesn't wipe the data--it can still be recovered. You have to sanitize it by overwriting the entire file with random bytes at least once before deleting it. Not good.

vor0nwe
Offline
Last seen: 5 years 4 months ago
Joined: 2006-03-09 12:11
Whoa! Easy...

...with the paranoia!

Most info my browser is caching is not that sensitive. If anyone really wanted to get at it, it would be easier to set up a packet sniffer somewhere upstream than trying to recover those cached files.
The more sensitive stuff usually goes over encrypted connections, and Firefox doesn't cache SSL connections anyway.

Martijn
--
Where is the trust?

--
"The Duke had a mind that ticked like a clock, and like a clock, it regularly went cuckoo."
-- Terry Pratchett, Wyrd Sisters

vor0nwe
Offline
Last seen: 5 years 4 months ago
Joined: 2006-03-09 12:11
:-)

I just tried that to see if Ff would still be as memory-hungry (it's a lot less), but I also noticed that it made it really slow, as John reminds us. Smile

It's not a permanent setting for me, but I can imagine people on PCs with less memory wanting to keep from eating up too much of it. I guess I'll just keep on recommending Opera to them...

--
"The Duke had a mind that ticked like a clock, and like a clock, it regularly went cuckoo."
-- Terry Pratchett, Wyrd Sisters

John T. Haller
John T. Haller's picture
Offline
Last seen: 7 hours 26 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
RAM Cache is dynamic

The RAM Firefox uses for cache is actually dynamic by default and based on the memory that a PC has. Even the fast back and forward pages are cached based on memory (from 0 to 8 pages are cached based on available RAM).

The thing with Opera is that it always uses a disk cache. Even when you tell it not to. The Opera USB project ran into this problem with running Opera from a flash drive. It still created a cache on the local PC in the TEMP directory... even when set not to. Making it not quite as portable as it should be.

Sometimes, the impossible can become possible, if you're awesome!

John T. Haller
John T. Haller's picture
Offline
Last seen: 7 hours 26 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
I'm with Bruce

Why on earth would you disable your ram cache in Firefox? That slows it down almost as much as running off a slow USB key does.

Sometimes, the impossible can become possible, if you're awesome!

Topic locked