Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Store states in Phalcon

I want to save some states of the application and the system as:

  • Modified date of a folder
  • The date of the last time it was run a CRON
  • etc...

Any good option to store this information?

Memcache/redis ?

You can start with simple files. Later move on to Memcached.

Some projects have a component * keyValueStore* and extends this to State component.

Although the best for now is to keep the states in a simple php file, perhaps using * var_export ().*

I created a service 'keyvalue:

My test:

 $storage = $this->keyvalue->get('state');
    $storage->set('mimi', [1, 'mimi']);
//    $storage->set('cerbero', [1,2,3,4]);
//    $storage->set('mimiz', "esto es un string");

    d($storage->getCollectionName());
    d($storage->getAll());
    d($storage->getMultiple(['mimi', 'cerbero']));
    d($storage->get('mimi'));
    d($storage->has('mimi'));
    d($storage->delete('mimiz'));
    d($storage->setMultiple([
        'tom' => ['soy', 'dios'],
        'garfield' => [1,2,3]
    ]));
    d($storage->rename('mimi', 'minimi'));


17.4k
Accepted
answer

extend keyvalue for state component

/**
     * @var \Druphal\Core\State\State $state
     */
    $state = $this->state;
    $state->delete('mimi');
    $state->set('system.date', time());
    $state->deleteMultiple(['mimi', 'mimi']);
    $state->get('mimi');
    $state->setMultiple([
        'system.not' => [1,2,3,4],
        'system.get' => 'mi mama me mima'
    ]);
    $state->getMultiple(['mimi']);

    d($state);