         if let existingNode = map[node.value.key] {
             remove(node: existingNode)
         }
-        
         list.append(node)
         map[node.value.key] = node
         totalCost += node.value.cost

                add(node: Node(value: CachedImage(image: image, cost: cost(image), key: key)))
                trim()
            } else {
                map[key].map(remove)
            }
        }
    }

            lock.lock()  // faster than `sync()`
            defer { lock.unlock() }

            guard let node = map[key] else { return nil }

            // bubble node up to the head
            list.remove(node)
            list.append(node)

            return node.value.image
        }
        set {
            lock.lock() // faster than `sync()`
