views:

150

answers:

3

I've developed an extension that creates alot* of data during a browsing session. Think, 2 to 3 times the total HTTP traffic (images, HTML, etc.).

Currently I'm just stashing all of this in a Javascript variable, but this obviously isn't tenable if the extension is going to get any serious usage.

So, the question is, where should I stash this data? Its very rarely accessed, but when it is ALL of it is. Additionally, it'd be nice if the data doesn't persist beyond the current session; stale data is useless in this case, and I'd rather not fill up disk needlessly.

*For something running in a browser, in Javascript

+1  A: 

You may want to look at the database that comes with Firefox 3.5.

https://developer.mozilla.org/en/Storage

James Black
A: 

On the disk. You wouldn't be able to keep it all in memory anyway if it's indeed 3x the traffic. You can always delete the no-longer-needed data at shutdown and/or at the start of the next session.

The specific way to store the data depends on the specific requirements you have - what you need to store, what is the patterns in the data access. If, as you say, you just need to save individual files received, I'd store them as files.

Nickolay
+1  A: 

A fairly standard solution is to use local files as storage. Code running as a Firefox extension has sufficient privileges to read and write local files. The MDC File I/O code snippets page is a very good starting point for understanding and implementing this in your extension. It also shows you how to find your extension's directory and illustrates the mechanism for creating temporary files.

These approaches should give you the tools you need to do what you're after. Let us know if you need further questions.

Tim