~ubuntu-branches/ubuntu/maverick/ilohamail/maverick

« back to all changes in this revision

Viewing changes to IlohaMail/include/cache.DB.inc

  • Committer: Bazaar Package Importer
  • Author(s): Joerg Jaspert
  • Date: 2004-02-04 13:44:37 UTC
  • Revision ID: james.westby@ubuntu.com-20040204134437-kz8j3ui2qa7oq8z2
Tags: upstream-0.8.12
ImportĀ upstreamĀ versionĀ 0.8.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/////////////////////////////////////////////////////////
 
3
//      
 
4
//      include/cache.FS.inc
 
5
//
 
6
//      (C)Copyright 2003 Ryo Chijiiwa <Ryo@IlohaMail.org>
 
7
//
 
8
//      This file is part of IlohaMail, and released under GPL.
 
9
//      See COPYING, or http://www.fsf.org/copyleft/gpl.html
 
10
//
 
11
/////////////////////////////////////////////////////////
 
12
/********************************************************
 
13
        PURPOSE: Unified interface to read/write cache
 
14
 
 
15
********************************************************/
 
16
 
 
17
$EXISTING_CACHES = array();
 
18
 
 
19
function cache_read($user, $host, $key){
 
20
        global $DB_CACHE_TABLE;
 
21
        global $EXISTING_CACHES;
 
22
        global $session_dataID;
 
23
        
 
24
        $db = new idba_obj;
 
25
        if (!$db->connect()) return false;
 
26
        
 
27
        $data = false;
 
28
        $sql = "SELECT * FROM $DB_CACHE_TABLE WHERE owner='$session_dataID' and cache_key='$key'";
 
29
        $result = $db->query($sql);
 
30
        if (($result) && ($db->num_rows($result)>0)){
 
31
                $a = $db->fetch_row($result);
 
32
                $data = unserialize($a["cache_data"]);
 
33
                $EXISTING_CACHES[$key] = $a["id"];
 
34
        }else{
 
35
                $result = false;
 
36
                $EXISTING_CACHES[$key] = false;
 
37
        }
 
38
                
 
39
        return $data;
 
40
}
 
41
 
 
42
function cache_write($user, $host, $key, $data, $volatile=true){
 
43
        global $DB_CACHE_TABLE;
 
44
        global $session_dataID;
 
45
                
 
46
        $db = new idba_obj;
 
47
        if (!$db->connect()) return false;
 
48
        
 
49
        if (!$EXISTING_CACHES[$key]){
 
50
                $sql = "SELECT id FROM $DB_CACHE_TABLE WHERE owner='$session_dataID' and cache_key='$key'";
 
51
                $result = $db->query($sql);
 
52
                if (($result) && ($db->num_rows($result)>0)){
 
53
                        $a = $db->fetch_row($result);
 
54
                        $EXISTING_CACHES[$key] = $a["id"];
 
55
                }else{
 
56
                        $EXISTING_CACHES[$key] = false;
 
57
                }
 
58
        }
 
59
        
 
60
        $data = serialize($data);
 
61
        if ($EXISTING_CACHES[$key]){
 
62
                $id = $EXISTING_CACHES[$key];
 
63
                $ownerID = $session_dataID;
 
64
                $sql = "UPDATE $DB_CACHE_TABLE SET cache_data='$data',volatile='$volatile' WHERE id='$id' AND owner='$session_dataID'";
 
65
                $result = $db->query($sql);     
 
66
        }else{
 
67
                $ownerID = $session_dataID;
 
68
                $sql = "INSERT INTO $DB_CACHE_TABLE (owner, cache_key, cache_data, cache_ts, volatile) ";
 
69
                $sql.= "VALUES ('$session_dataID', '$key', '$data', '".time()."', '$volatile')";
 
70
                $result = $db->query($sql);     
 
71
        }
 
72
                
 
73
        return $result;
 
74
}
 
75
 
 
76
function cache_clear($user, $host, $key){
 
77
        global $DB_CACHE_TABLE;
 
78
        global $session_dataID;
 
79
                
 
80
        $db = new idba_obj;
 
81
        if (!$db->connect()) return false;
 
82
        
 
83
        $sql = "UPDATE $DB_CACHE_TABLE SET cache_data='' WHERE owner='$session_dataID' and cache_key=$key'";
 
84
        return  $db->query($sql);               
 
85
}
 
86
 
 
87
function cache_clear_all($user, $host){
 
88
        global $session_dataID;
 
89
        global $DB_CACHE_TABLE;
 
90
        
 
91
        $db = new idba_obj;
 
92
        if (!$db->connect()) return false;
 
93
 
 
94
        $expire = time() - (60 * 60 * 24 * 30);  //timestamp 30 days ago
 
95
        $sql = "DELETE FROM $DB_CACHE_TABLE ";
 
96
        $sql.= " WHERE (owner='$session_dataID' and volatile='1')";
 
97
        $sql.= " OR (cache_ts < '$expire' and volatile='1')";
 
98
        return $db->query($sql);
 
99
}
 
100
 
 
101
?>
 
 
b'\\ No newline at end of file'