pauamma: Cartooney crab wearing hot pink and acid green facemask holding drink with straw (Default)
Res facta quae tamen fingi potuit ([personal profile] pauamma) wrote in [site community profile] dw_dev2010-05-12 09:33 pm
Entry tags:

Using LJ::Typemap outside web context: how to initialize LJ::MemCache?

LJ::Typemap calls LJ::MemCache, but doesn't actually "use LJ::MemCache;" or call LJ::MemCache::init, relying instead on ljlib.pl to do both. In web context, ljlib.pl is loaded through Apache::LiveJournal, and for worker processes, through LJ::Worker::Manual. For other executables (eg, proof of concept, throwaway learning tools, etc) which don't fall in either category, what should happen?

Options are:
1- Make LJ::Typemap (and everything else that relies on LJ::MemCache) use it and initialize it explicitely. This requires changes to LJ::MemCache, because LJ::MemCache::init isn't currently idempotent.
2- Require all programs using LJ::MemCache to use base 'LJ::Worker::Manual'; (but that in turn requires making them workers, with a LJ::Worker::Foo package that's started from main, which is awkward for throw-away programs).
3- Make LJ::MemCache initialize itself when loaded, and remove explicit initialization from everywhere else that uses it, but that's extensive.
4- Something else I forgot.

I'm leaning toward 2 ATM. Anyone has a better solution, an opinion, or comments?
zorkian: Icon full of binary ones and zeros in no pattern. (Default)

[personal profile] zorkian 2010-05-12 11:25 pm (UTC)(link)
Everything should load ljlib at the top. All my tools start with

Use strict
Use lib ljhome/cgi-bin
Require ljlib.pl

Am on train so not logging in as mark or typing proper code.