From a583fb71e1a3c4a99ecb8742168ad71c3b289b55 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Mon, 9 Sep 2019 15:24:19 -0400 Subject: remove caching --- sumdb/client.go | 90 ++------------------------------------------------------- 1 file changed, 3 insertions(+), 87 deletions(-) (limited to 'sumdb') diff --git a/sumdb/client.go b/sumdb/client.go index e4552ae..8943eb3 100644 --- a/sumdb/client.go +++ b/sumdb/client.go @@ -48,16 +48,6 @@ type ClientOps interface { // The "key" configuration file is never written using WriteConfig. WriteConfig(file string, old, new []byte) error - // ReadCache reads and returns the content of the named cache file. - // Any returned error will be treated as equivalent to the file not existing. - // There can be arbitrarily many cache files, such as: - // serverName/lookup/pkg@version - // serverName/tile/8/1/x123/456 - ReadCache(file string) ([]byte, error) - - // WriteCache writes the named cache file. - WriteCache(file string, data []byte) - // Log prints the given log message (such as with log.Print) Log(msg string) @@ -210,14 +200,9 @@ func (c *Client) Lookup(path, vers string) (lines []string, err error) { } result := c.record.Do(file, func() interface{} { // Try the on-disk cache, or else get from web. - writeCache := false - data, err := c.ops.ReadCache(file) + data, err := c.ops.ReadRemote(remotePath) if err != nil { - data, err = c.ops.ReadRemote(remotePath) - if err != nil { - return cached{nil, err} - } - writeCache = true + return cached{nil, err} } // Validate the record before using it for anything. @@ -232,12 +217,6 @@ func (c *Client) Lookup(path, vers string) (lines []string, err error) { return cached{nil, err} } - // Now that we've validated the record, - // save it to the on-disk cache (unless that's where it came from). - if writeCache { - c.ops.WriteCache(file, data) - } - return cached{data, nil} }).(cached) if result.err != nil { @@ -506,60 +485,7 @@ func (c *Client) tileRemotePath(tile tlog.Tile) string { // readTile reads a single tile, either from the on-disk cache or the server. func (c *Client) readTile(tile tlog.Tile) ([]byte, error) { - type cached struct { - data []byte - err error - } - - result := c.tileCache.Do(tile, func() interface{} { - // Try the requested tile in on-disk cache. - data, err := c.ops.ReadCache(c.tileCacheKey(tile)) - if err == nil { - c.markTileSaved(tile) - return cached{data, nil} - } - - // Try the full tile in on-disk cache (if requested tile not already full). - // We only save authenticated tiles to the on-disk cache, - // so the recreated prefix is equally authenticated. - full := tile - full.W = 1 << uint(tile.H) - if tile != full { - data, err := c.ops.ReadCache(c.tileCacheKey(full)) - if err == nil { - c.markTileSaved(tile) // don't save tile later; we already have full - return cached{data[:len(data)/full.W*tile.W], nil} - } - } - - // Try requested tile from server. - data, err = c.ops.ReadRemote(c.tileRemotePath(tile)) - if err == nil { - return cached{data, nil} - } - - // Try full tile on server. - // If the partial tile does not exist, it should be because - // the tile has been completed and only the complete one - // is available. - if tile != full { - data, err := c.ops.ReadRemote(c.tileRemotePath(full)) - if err == nil { - // Note: We could save the full tile in the on-disk cache here, - // but we don't know if it is valid yet, and we will only find out - // about the partial data, not the full data. So let SaveTiles - // save the partial tile, and we'll just refetch the full tile later - // once we can validate more (or all) of it. - return cached{data[:len(data)/full.W*tile.W], nil} - } - } - - // Nothing worked. - // Return the error from the server fetch for the requested (not full) tile. - return cached{nil, err} - }).(cached) - - return result.data, result.err + return c.ops.ReadRemote(c.tileRemotePath(tile)) } // markTileSaved records that tile is already present in the on-disk cache, @@ -585,14 +511,4 @@ func (r *tileReader) SaveTiles(tiles []tlog.Tile, data [][]byte) { } } c.tileSavedMu.Unlock() - - for i, tile := range tiles { - if save[i] { - // If WriteCache fails here (out of disk space? i/o error?), - // c.tileSaved[tile] is still true and we will not try to write it again. - // Next time we run maybe we'll redownload it again and be - // more successful. - c.ops.WriteCache(c.name+"/"+tile.Path(), data[i]) - } - } } -- cgit v1.2.3