Branch: Tag:

2001-01-01

2001-01-01 22:49:44 by Francesco Chemolli <li@kinkie.it>

Added code to address dependencies and chain-deletion of cache entries.

Rev: lib/modules/Cache.pmod/Policy.pmod/Timed.pike:1.4
Rev: lib/modules/Cache.pmod/Storage.pmod/Base.pike:1.5
Rev: lib/modules/Cache.pmod/Storage.pmod/Gdbm.pike:1.6
Rev: lib/modules/Cache.pmod/Storage.pmod/Memory.pike:1.5
Rev: lib/modules/Cache.pmod/Storage.pmod/Yabu.pike:1.7
Rev: lib/modules/Cache.pmod/cache.pike:1.5

3:    * by Francesco Chemolli <kinkie@roxen.com>    * (C) 2000 Roxen IS    * -  * $Id: Memory.pike,v 1.4 2000/09/28 03:38:31 hubbe Exp $ +  * $Id: Memory.pike,v 1.5 2001/01/01 22:49:43 kinkie Exp $    *    * This storage manager provides the means to save data to memory.    * In this manager I'll add reference documentation as comments to
20:       int _size=0;    mixed _data=0; +  multiset(string) _deps;       void create(void|mixed value, void|int abs_expire_time, -  void|float preciousness) { +  void|float preciousness, +  void|multiset(string) dependants) {    _data=value;    atime=ctime=time(1);    if (abs_expire_time) etime=abs_expire_time;    if (preciousness) cost=preciousness; -  +  if (dependants) _deps=dependants;    }       int size() {
75:   }      int(0..0)|string next() { -  if (iter && current < sizeof(iter)) +  if (iter && current < sizeof(iter) && data[iter[current]])    return iter[current++];    iter=0;    return 0;
88:    */   void set(string key, mixed value,    void|int absolute_expire, -  void|float preciousness) { -  data[key]=Data(value,absolute_expire,preciousness); +  void|float preciousness, +  void|multiset(string) dependants) { +  data[key]=Data(value,absolute_expire,preciousness,dependants);   }      // fetches some data from the cache. If notouch is set, don't touch the
109:      void delete(string key, void|int(0..1) hard) {    object(Cache.Data) rv=data[key]; +  if (!rv) return; +  multiset deps=rv->_deps; +  +  //need to destruct this first, or we might infinite-loop recursing +  //through the dependants (think of a bug listing a value depending +  //on itself, or even worse, circularly.    if (hard) {    destruct(rv->value());    }    m_delete(data,key); -  +  +  if (deps) { +  foreach((array)(deps), string dep) { +  delete(dep,hard); +  } +  }    return 0;   }