annotate pkg/octree/cache.go @ 725:e0437ec46798

Finished the octree cache. TODO: implement the deserialization.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 22 Sep 2018 09:55:42 +0200
parents 6ab0c170e5b8
children 41c8dc61f38f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
1 package octree
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import (
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 "context"
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 "database/sql"
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 "sync"
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 "time"
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 )
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 type (
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
11 cacheKey struct {
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 date time.Time
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 bottleneck string
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 }
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
16 cacheEntry struct {
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 checksum string
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 tree *Octree
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 access time.Time
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 }
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
21 OctreeCache struct {
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 sync.Mutex
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
23 entries map[cacheKey]*cacheEntry
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 }
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 )
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 const (
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
28 cleanupCacheSleep = 6 * time.Minute
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
29 maxCacheAge = 5 * time.Minute
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
30 maxCacheEntries = 4
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 )
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 const (
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 fetchOctreeSQL = `
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 SELECT checksum, octree_index
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 FROM waterway.octrees ot
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 JOIN waterway.sounding_results sr ON ot.sounding_result_id = sr.id
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 WHERE sr.bottleneck_id = $1 AND sr.date_info = $2::date
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 `
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 checkOctreeSQL = `
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 SELECT CASE
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 WHEN checksum = $3 THEN NULL
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 ELSE ot.octree_index
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 END
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 FROM waterway.octrees ot
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 JOIN waterway.sounding_results sr ON ot.sounding_result_id = sr.id
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 WHERE sr.bottleneck_id = $1 AND sr.date_info = $2::date
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 `
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 )
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
51 var Cache = OctreeCache{
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
52 entries: map[cacheKey]*cacheEntry{},
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 }
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 func init() {
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
56 go Cache.background()
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 }
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
59 func (oc *OctreeCache) background() {
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 for {
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
61 time.Sleep(cleanupCacheSleep)
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 oc.cleanup()
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
66 func (oc *OctreeCache) cleanup() {
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 oc.Lock()
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 defer oc.Unlock()
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
69 good := time.Now().Add(-maxCacheAge)
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 for k, v := range oc.entries {
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 if v.access.Before(good) {
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 delete(oc.entries, k)
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 }
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 }
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 }
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
77 func (oc *OctreeCache) Get(
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 bottleneck string, date time.Time,
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 conn *sql.Conn, ctx context.Context,
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 ) (*Octree, error) {
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 oc.Lock()
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 defer oc.Unlock()
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83
724
6ab0c170e5b8 Moved octree stuff to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 723
diff changeset
84 key := cacheKey{date, bottleneck}
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 entry := oc.entries[key]
725
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
86
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
87 var data []byte
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
88 var checksum string
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
89
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 if entry == nil {
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 // fetch from database
725
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
92 err := conn.QueryRowContext(
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
93 ctx, fetchOctreeSQL, bottleneck, date).Scan(&checksum, &data)
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
94 switch {
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
95 case err == sql.ErrNoRows:
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
96 return nil, nil
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
97 case err != nil:
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
98 return nil, err
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
99 }
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
100 } else {
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
101 // check if we are not outdated.
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
102 err := conn.QueryRowContext(
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
103 ctx, checkOctreeSQL, bottleneck, date, entry.checksum).Scan(&data)
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 switch {
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 case err == sql.ErrNoRows:
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 return nil, nil
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 case err != nil:
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 return nil, err
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 }
725
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
110 if data == nil { // we are still current
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
111 entry.access = time.Now()
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
112 return entry.tree, nil
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
113 }
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
114 }
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
115
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
116 tree, err := Deserialize(data)
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
117 if err != nil {
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
118 return nil, err
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
119 }
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
120
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
121 now := time.Now()
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
122
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
123 if entry != nil {
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
124 entry.tree = tree
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
125 entry.access = now
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
126 return tree, nil
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 }
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128
725
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
129 for len(oc.entries) >= maxCacheEntries {
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
130 // Evict the entry that is accessed the longest time ago.
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
131 var oldestKey cacheKey
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
132 oldest := now
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
133
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
134 for k, v := range oc.entries {
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
135 if v.access.Before(oldest) {
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
136 oldest = v.access
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
137 oldestKey = k
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
138 }
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
139 }
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
140 delete(oc.entries, oldestKey)
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
141 }
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
142
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
143 oc.entries[key] = &cacheEntry{
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
144 checksum: checksum,
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
145 tree: tree,
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
146 access: now,
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
147 }
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
148
e0437ec46798 Finished the octree cache. TODO: implement the deserialization.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 724
diff changeset
149 return tree, nil
723
7eed7ff3142d Started with model to load octrees from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 }