github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/remotestorage/chunk_cache.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package remotestorage 16 17 import ( 18 "github.com/dolthub/dolt/go/store/hash" 19 "github.com/dolthub/dolt/go/store/nbs" 20 ) 21 22 // ChunkCache is an interface used for caching chunks 23 type ChunkCache interface { 24 // Put puts a slice of chunks into the cache. 25 Put(c []nbs.CompressedChunk) 26 27 // Get gets a map of hash to chunk for a set of hashes. In the event that a chunk is not in the cache, chunks.Empty. 28 // is put in it's place 29 Get(h hash.HashSet) map[hash.Hash]nbs.CompressedChunk 30 31 // Has takes a set of hashes and returns the set of hashes that the cache currently does not have in it. 32 Has(h hash.HashSet) (absent hash.HashSet) 33 34 // PutChunk puts a single chunk in the cache. true returns in the event that the chunk was cached successfully 35 // and false is returned if that chunk is already is the cache. 36 PutChunk(chunk nbs.CompressedChunk) bool 37 38 // GetAndClearChunksToFlush gets a map of hash to chunk which includes all the chunks that were put in the cache 39 // between the last time GetAndClearChunksToFlush was called and now. 40 GetAndClearChunksToFlush() map[hash.Hash]nbs.CompressedChunk 41 }