| 54 | } |
| 55 | |
| 56 | int WSITileGraphicsItemCache::set(const keyType& k, WSITileGraphicsItem* v, unsigned int size, bool topLevel) { |
| 57 | if (_cache.find(k) != _cache.end()) { |
| 58 | return 1; |
| 59 | } |
| 60 | if (size > _cacheMaxByteSize) { |
| 61 | return 1; |
| 62 | } |
| 63 | while (_cacheCurrentByteSize + size > _cacheMaxByteSize && _cacheCurrentByteSize != 0) { |
| 64 | evict(); |
| 65 | } |
| 66 | |
| 67 | // Do not add to the LRU if it is a top-level item so it is never removed |
| 68 | if (!topLevel) { |
| 69 | keyTypeList::iterator it = _LRU.insert(_LRU.end(), k); |
| 70 | _cache[k] = std::make_pair(std::make_pair(v, size), it); |
| 71 | } |
| 72 | else { |
| 73 | _cache[k] = std::make_pair(std::make_pair(v, size), _LRU.end()); |
| 74 | } |
| 75 | _cacheCurrentByteSize += size; |
| 76 | return 0; |
| 77 | } |