I often find myself wanting to store a simple piece of information such as 'last exported id' or 'last import date' for retrieval at a later point in time. This is the kind of information that will always have a value, but will change frequently. Does anybody have any recommendations of a best practice, or even just passable place for storing this information?

I've considered making them config options, but since they are the kind of information that will change frequently in an automated fashion, and I don't want the end-user to modify the information, this doesn't feel like a good fit.

It needs to be global and permanent (changeable, but always available) so something like storing it in the session is out of the question.

I recently came across core_variable, which may be appropriate, but I've never come across a single use of it, so have no idea if it's suitable or even stable, let alone how to use it. If anybody has any examples that would be grand.


Use a configuration setting.

There is no need to have an entry in system.xml or a default in config.xml.

Just write it directly to the database:

Mage::app()->getConfig()->saveConfig(self::PATH_TO_YOUR_CONFIG, $value);
  • That's one option, never really occurred to me to use it without adding the configuration. – Peter O'Callaghan Nov 7 '13 at 21:42
  • 2
    How do you manage row locks when things like last order number could constantly be changing? – philwinkle Nov 7 '13 at 21:46
  • Interesting question, but in my particular instances, this wouldn't likely be an issue. Most of the things I will be storing will be identifiers/pointers for scheduled tasks so they can keep track of progress. Thus the variables will only be updated once per cycle, which is likely to be measure in hours or possibly minutes, but not frequent enough to cause locking issues. For example paging through a remote api, and storing highest ID for use as min_id param in next cycles query. – Peter O'Callaghan Nov 7 '13 at 22:04
  • 1
    I never thought about this @philwinkle but the stores I work for a small enough to not think about this... – Fabian Blechschmidt Nov 8 '13 at 21:25
  • 1
    @FabianBlechschmidt this is a big problem when customers have something like a flash-sale - lots of lock contention. we've learned how to circumvent it. – philwinkle Nov 8 '13 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.