Statistics
| Branch: | Revision:

root / src / pithos / content / cache.js @ 71:7dde618cb775

History | View | Annotate | Download (2.8 kB)

1
// The Pithos File Manager Firefox Extension is funded by GRNET S.A.
2
// (http://www.grnet.gr)
3
//
4
// Copyright (c) 2009, Christos KK Loverdos, Vassilios Karakoidas.
5
// All rights reserved.
6
//
7
// Redistribution and use in source and binary forms, with or without
8
// modification, are permitted provided that the following conditions are
9
// met:
10
//
11
//   - Redistributions of source code must retain the above copyright
12
//     notice, this list of conditions and the following disclaimer.
13
//   - Redistributions in binary form must reproduce the above
14
//     copyright notice, this list of conditions and the following
15
//     disclaimer in the documentation and/or other materials provided
16
//     with the distribution.
17
//   - Neither the name of GRNET S.A. nor the names of its contributors
18
//     may be used to endorse or promote products derived from this
19
//     software without specific prior written permission.
20
//
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32

    
33
cache = null;
34

    
35
// Directory caching
36
function FileCache() {
37
        // public properties
38
        
39
        // private properties
40
        var cacheMap = new Array();
41
        var cacheExpired = new Array();
42
        var cacheExceptions = new Array();
43
        var expiration = 60000; // 1 minute for expiration of data
44
        
45
        // public methods
46
        this.add = function(key, obj) {
47
                if ( cacheExceptions.indexOf(key) >= 0) {
48
                        return;
49
                }
50
                var d = new Date();
51
                
52
                cacheMap[key] = obj;
53
                cacheExpired[key] = d.getTime();
54
        }
55
        
56
        this.remove = function(key) {
57
                cacheMap[key] = undefined;
58
                cacheExpired[key] = 0;                
59
        }
60
        
61
        this.get = function(key) {
62
                var d = new Date();
63
                var e = cacheExpired[key];
64
                
65
                // the key should exist in the cacheExpired map
66
                if (e == undefined) { return undefined; }
67
                
68
                // if the data are expired
69
                if (((d.getTime() - e) > expiration) || (e == 0)) {
70
                        cacheMap[key] = undefined;
71
                        cacheExpired[key] = 0;
72
                        
73
                        return undefined; 
74
                }
75
                
76
                return cacheMap[key];
77
        }
78
        
79
        // private methods
80
        
81
        // initialisation
82
    // never cache shared and others
83
        cacheExceptions.push(connection_obj.user_homepage().shared);
84
        cacheExceptions.push(connection_obj.user_homepage().others);
85
        cacheExceptions.push(connection_obj.user_homepage().trash);
86
}