12 CacheItemBase::CacheItemBase()
13 : ListItem<CacheItemBase>()
20 CacheItemBase::~CacheItemBase()
22 free(path); // path was allocated with strdup in FramceCache::put_frame()
28 int CacheItemBase::get_size()
37 CacheBase::CacheBase()
38 : List<CacheItemBase>()
40 lock = new Mutex("CacheBase::lock");
44 CacheBase::~CacheBase()
51 int CacheBase::get_age()
53 return EDL::next_id();
57 // Called when done with the item returned by get_.
58 // Ignore if item was 0.
59 void CacheBase::unlock()
64 void CacheBase::remove_all()
67 lock->lock("CacheBase::remove_all");
75 //printf("CacheBase::remove_all: removed %d entries\n", total);
79 void CacheBase::remove_asset(Asset *asset)
82 lock->lock("CacheBase::remove_id");
83 for(current_item = first; current_item; )
85 if(current_item->path && !strcmp(current_item->path, asset->path) ||
86 current_item->asset_id == asset->id)
88 CacheItemBase *next = current_item->next;
94 current_item = current_item->next;
97 //printf("CacheBase::remove_asset: removed %d entries for %s\n", total, asset->path);
100 int CacheBase::get_oldest()
102 int oldest = 0x7fffffff;
103 lock->lock("CacheBase::get_oldest");
104 for(CacheItemBase *current = first; current; current = NEXT)
106 if(current->age < oldest)
107 oldest = current->age;
115 int CacheBase::delete_oldest()
117 int oldest = 0x7fffffff;
118 CacheItemBase *oldest_item = 0;
120 lock->lock("CacheBase::delete_oldest");
121 for(CacheItemBase *current = first; current; current = NEXT)
123 if(current->age < oldest)
125 oldest = current->age;
126 oldest_item = current;
132 // Too much data to debug if audio.
133 // printf("CacheBase::delete_oldest: deleted position=%lld %d bytes\n",
134 // oldest_item->position, oldest_item->get_size());
136 if(current_item == oldest_item) current_item = 0;
146 int64_t CacheBase::get_memory_usage()
149 lock->lock("CacheBase::get_memory_usage");
150 for(CacheItemBase *current = first; current; current = NEXT)
152 result += current->get_size();
158 void CacheBase::put_item(CacheItemBase *item)
160 // Get first position >= item
161 if(!current_item) current_item = first;
162 while(current_item && current_item->position < item->position)
163 current_item = current_item->next;
164 if(!current_item) current_item = last;
165 while(current_item && current_item->position >= item->position)
166 current_item = current_item->previous;
168 current_item = first;
170 current_item = current_item->next;
178 insert_before(current_item, item);
181 // Get first item from list with matching position or 0 if none found.
182 CacheItemBase* CacheBase::get_item(int64_t position)
184 if(!current_item) current_item = first;
185 while(current_item && current_item->position < position)
186 current_item = current_item->next;
187 if(!current_item) current_item = last;
188 while(current_item && current_item->position >= position)
189 current_item = current_item->previous;
191 current_item = first;
193 if(current_item->next)
194 current_item = current_item->next;
195 if(!current_item || current_item->position != position) return 0;