1 // Copyright 2018 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <digest/digest.h> 6 7 #include <blobfs/blob-cache.h> 8 #include <blobfs/cache-node.h> 9 10 using digest::Digest; 11 12 namespace blobfs { 13 fbl_recycle()14void CacheNode::fbl_recycle() { 15 if (ShouldCache()) { 16 // Migrate from the open cache to the closed cache, keeping the Vnode alive. 17 // 18 // If the node has already been evicted, it is destroyed. 19 Cache().Downgrade(this); 20 } else { 21 // Destroy blobs which don't want to be cached. 22 // 23 // If we're deleting this node, it must not exist in either hash. 24 Cache().EvictUnsafe(this, true); 25 ZX_DEBUG_ASSERT(!InContainer()); 26 delete this; 27 } 28 } 29 30 CacheNode::CacheNode() = default; 31 CacheNode(const Digest & digest)32CacheNode::CacheNode(const Digest& digest) { 33 digest.CopyTo(digest_, sizeof(digest_)); 34 } 35 CacheNode::~CacheNode() = default; 36 37 } // namespace blobfs 38