memcached using a dll

 

Does anyone tried to use memcached for data caching?
I have indicators that take a long time to calculate and as long as I don't expect a value to change, I would like to take the value from cache.


I love memcahced, but I wasn't able to find a usable dll with exported functions.
Help will be strongly appreciated. 

Thanks. 

 

P.S.

Other caching solutions might be good as well. 

 
you don't need to go via memcached. calculate your data and store it in static variables. in experts global variables are static out of the box. in indicators not, but data stored in another module (ie. a library) is static. write a getter/setter expecting/returning an array with your data and put it in a library.
 

The thing is that the data is not static and might change depending on parameters so I would like to update it from time to time.
Memcached will be ideal for that!

 
fudge:

The thing is that the data is not static and might change depending on parameters so I would like to update it from time to time.
Memcached will be ideal for that!


you might think so because you might not know the implementation details of caches. memcached takes the burden to manage the expiration settings from you. if you do it by yourself there is no need for a 3rd party cache. you just not only store the data value but also the expiration setting: cachedValue = {$key, $expiration, $value}. whenever you need your data your getter does an additional expiration check. if expired, it deletes the value from cache and returns NULL. in fact thats exactly what memcached and friends are doing, you just don't see it. do it on your own and you'r fine.


public function Cache::get($key) {

      // cache lookup
      $data = cache_fetch($key);
      if (!$data)             // cache-miss
         return NULL;

      // cache-hit, data format: array(created, expires, value)
      $created = $data[0];
      $expires = $data[1];
      $value   = $data[2];

      // expiration checking
      if ($expires < time()) {
         cache_drop($key);
         return NULL;
      }

      return unserialize($value);
}

for different values per parameters you store every data set under a different key.

regards

 
actually i really can't see a serious reason to use a 3rd party cache. if you really believe you need one you should 1st try to find a better implementation algorythm to solve your specific problem. as a last resort i would consider a simple file cache implementation. frequently accessed files are stored in memory anyway, so access time cannot be the point.
 

There are many reasons to use 3rd party stuff without implementing it by yourself.
Memcached is a distributed cache which can be accessed by multiple processes from multiple machines. There is no reason to try and implement this functionality if someone already did this for you and offers it for free.

If someone was able to use memcached in MQL4 I would love to know. 

Thanks.

 

I understand why you are looking for such feature.

I would like a map (dictionary), associative array into MetaTrader but I didn't find a decent implementation.

http://en.wikipedia.org/wiki/Associative_array

http://en.wikipedia.org/wiki/Key-value_data_store