How to implement non-permanent application cache

How to implement non-permanent application cache

by Zoran Jeremic -
Number of replies: 3
Hi,

I'm developing plugin for Moodle 2.6 and I have an application variable that checks if an instance of RabbitMQ consumer is started or not, so it doesn't start another one. Right now, I have something like this:

$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'local_morph', 'rabbitmqconsumer');
$cache->set('enabled','true');
$enabled=$cache->get('enabled');

It works, but the problem is that this variable is permanent, and in case of apache restart I need to clean the cache in order to return variable to default state. Is it possible to make this variable non-permanent, without installing memcache data store?

Thanks,
Zoran


Average of ratings: -
In reply to Zoran Jeremic

Re: How to implement non-permanent application cache

by Darko Miletić -

No. And I do not see how would memcached help you here since it runs in separate process unrelated to web server.

The appropriate way to deal with this issue would be to detect when did web server start (on LAMP that can be determined by examining pid file timestamp) and encode that information into cache value (key name etc.). Upon every execution you compare the key timestamp with server timestamp. When they differ it is time for reset.

Of course this is not the most fortunate way of doing this. Ideally it might be possible to use apache SetEnv to define env variable pointing to pid file so as to avoid hardcoding.

Average of ratings: Useful (1)
In reply to Darko Miletić

Re: How to implement non-permanent application cache

by Zoran Jeremic -

Hi Darko,


Great idea. This solved my problem completely.

Is it possible to make something similar for Windows platform? I don't have Windows to try it right now, but it would be good to know that I can apply similar solution.


Thanks,

Zoran


In reply to Zoran Jeremic

Re: How to implement non-permanent application cache

by Darko Miletić -

Of course it is possible but I have no idea how to do it. Process management is completely different in Windows.

Perhaps a more portable solution would be to use APC and it's cache store.

http://php.net/manual/en/ref.apc.php

Of course that would not work if PHP is installed as php-fpm.