6

I'm using PhantomJS 1.8 and ran into a limitation -- you can't specify what directory it uses for the disk cache. I added this to their issue tracking system, but since it wasn't in there before, I wouldn't expect it to be added soon.

So, I'm looking for some way around this limitation. What I'm trying to do is have multiple Phantomjs processes running, each with their own, separate, cache directory. Is there a way I can do this until the feature gets added to phantom?

How does phantom even determine which directory to use for cache in the first place? If it's based on an environment variable, maybe there could be some way I set a different value for that variable for each instance of PhantomJS that I have running.

Borys
  • 511
  • 3
  • 7
  • Did you figure this out? How did you get multiple instances to work anyway? I tried using a separate child process for each, but it didn't seem to work. – Josh C. Apr 21 '13 at 05:00
  • 1
    Unfortunately, as of PhantomJS 1.8 there's no way to pass in a cache directory, so all calls share the same cache if you are using one. I'm not sure if there's been an update to fix this, but I created a feature request for it: https://github.com/ariya/phantomjs/issues/11102 . As for how I ran multiple instances, I chose option #2 from this answer: http://stackoverflow.com/a/9978162 . – Borys Apr 22 '13 at 12:45
  • Ah, I went down the path of option #1 because I'm passing a javascript function for the page to evaluate, and option #1 seemed easier for me. I wrapped the nodejs module in its own child process. However, I can't seem to make two calls with two child processes concurrently. – Josh C. Apr 22 '13 at 14:12

1 Answers1

2

Under PhantomJS 1.9 at least, the cache directory is $HOME/.qws/cache/Ofi Labs/PhantomJS, so if you modify the HOME environment variable before running PhantomJS, you could have a different disk cache for each process. I tested this and it works for me.

Bluby
  • 321
  • 2
  • 6