Mercurial > hg > orthanc
comparison Core/Cache/MemoryCache.cpp @ 288:40d3bf6cc8d9
logs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 Dec 2012 11:22:04 +0100 |
parents | 4031f73fe0e4 |
children | 4d7469f72a0b |
comparison
equal
deleted
inserted
replaced
287:471df5fecb1e | 288:40d3bf6cc8d9 |
---|---|
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #include "MemoryCache.h" | 33 #include "MemoryCache.h" |
34 | 34 |
35 #include <glog/logging.h> | |
36 | |
35 namespace Orthanc | 37 namespace Orthanc |
36 { | 38 { |
37 MemoryCache::Page& MemoryCache::Load(const std::string& id) | 39 MemoryCache::Page& MemoryCache::Load(const std::string& id) |
38 { | 40 { |
39 // Reuse the cache entry if it already exists | 41 // Reuse the cache entry if it already exists |
40 Page* p = NULL; | 42 Page* p = NULL; |
41 if (index_.Contains(id, p)) | 43 if (index_.Contains(id, p)) |
42 { | 44 { |
45 VLOG(1) << "Reusing a cache page"; | |
43 assert(p != NULL); | 46 assert(p != NULL); |
44 index_.TagAsMostRecent(id); | 47 index_.TagAsMostRecent(id); |
45 return *p; | 48 return *p; |
46 } | 49 } |
47 | 50 |
48 // The id is not in the cache yet. Make some room if the cache | 51 // The id is not in the cache yet. Make some room if the cache |
49 // is full. | 52 // is full. |
50 if (index_.GetSize() == cacheSize_) | 53 if (index_.GetSize() == cacheSize_) |
51 { | 54 { |
55 VLOG(1) << "Dropping the oldest cache page"; | |
52 index_.RemoveOldest(p); | 56 index_.RemoveOldest(p); |
53 delete p; | 57 delete p; |
54 } | 58 } |
55 | 59 |
56 // Create a new cache page | 60 // Create a new cache page |
57 std::auto_ptr<Page> result(new Page); | 61 std::auto_ptr<Page> result(new Page); |
58 result->id_ = id; | 62 result->id_ = id; |
59 result->content_.reset(provider_.Provide(id)); | 63 result->content_.reset(provider_.Provide(id)); |
60 | 64 |
61 // Add the newly create page to the cache | 65 // Add the newly create page to the cache |
66 VLOG(1) << "Registering new data in a cache page"; | |
62 p = result.release(); | 67 p = result.release(); |
63 index_.Add(id, p); | 68 index_.Add(id, p); |
64 return *p; | 69 return *p; |
65 } | 70 } |
66 | 71 |