1
# PiTiVi , Non-linear video editor
5
# Copyright (c) 2009, Brandon Lewis (brandon_lewis@berkeley.edu)
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU Lesser General Public
9
# License as published by the Free Software Foundation; either
10
# version 2.1 of the License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# Lesser General Public License for more details.
17
# You should have received a copy of the GNU Lesser General Public
18
# License along with this program; if not, write to the
19
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20
# Boston, MA 02110-1301, USA.
23
Dictionary-Like object for caching of thumbnails.
29
class ThumbnailCache(object):
31
"""Caches thumbnails by key using LRU policy, implemented with heapq"""
33
def __init__(self, size=100):
35
self.queue = collections.deque()
41
def __contains__(self, key):
48
def __getitem__(self, key):
50
# I guess this is why LRU is considered expensive
51
self.queue.remove(key)
52
self.queue.append(key)
53
return self.cache[key]
56
def __setitem__(self, key, value):
57
self.cache[key] = value
58
self.queue.append(key)
59
if len(self.cache) > self.size:
63
key = self.queue.popleft()