File: Data.pike

package info (click to toggle)
pike8.0 8.0.1956-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 60,580 kB
  • sloc: ansic: 259,734; xml: 36,320; makefile: 3,748; sh: 1,713; cpp: 1,349; awk: 1,036; lisp: 655; javascript: 468; asm: 242; objc: 240; pascal: 157; sed: 34
file content (50 lines) | stat: -rw-r--r-- 1,505 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Base storage-object for the cache system
 * by Francesco Chemolli <kinkie@roxen.com>
 */

//! Base stored object for the cache system.

#pike __REAL_VERSION__

int atime=0; //! last-access time.
int ctime=0; //! creation-time
int etime=0; //! expiry-time (if supplied). 0 otherwise
float cost=1.0; //! relative preciousness scale

void touch() { //used by the Storage Manager mainly.
  atime=time(1);
}

//! expire_time is relative and in seconds.
void create(void|mixed value, void|int expire_time, void|float preciousness) {
  atime=ctime=time(1);
}

int size() {} //! A method in order to allow for lazy computation.
              //! Used by some Policy Managers

mixed data() {} //! A method in order to allow for lazy computation


#define DEFAULT_SIZE 2048

//! Attempts a wild guess of an object's size.
//! It's left here as a common utility. Some classes won't even need it.
int recursive_low_size(mixed whatfor) {
  if (stringp(whatfor)) return sizeof(whatfor);
  if (intp(whatfor)) return SIZEOF_INT; //NOTE: not true for bignums...
  if (floatp(whatfor)) return SIZEOF_FLOAT;
  if (programp(whatfor) || objectp(whatfor) || 
      functionp(whatfor)) return DEFAULT_SIZE;
  // only composite types ahead
  array(mixed) iter;
  int size=sizeof(whatfor);
  if (arrayp(whatfor)) iter=whatfor;
  if (mappingp(whatfor)) iter=indices(whatfor)+values(whatfor);
  if (multisetp(whatfor)) iter=indices(whatfor);
  foreach(iter,mixed tmp) {
    size+=recursive_low_size(tmp);
  }
  return size;
}