Documentation
¶
Overview ¶
Package cdc provides support for reading Chromium disk cache v2. https://www.chromium.org/developers/design-documents/network-stack/disk-cache
Example ¶
Example gets an entry from the cache and prints to stdout.
package main
import (
"fmt"
"image/png"
"log"
"github.com/schorlet/cdc"
)
func main() {
cache, err := cdc.OpenCache("testcache")
if err != nil {
log.Fatal(err)
}
entry, err := cache.OpenURL("https://golang.org/doc/gopher/pkg.png")
if err != nil {
log.Fatal(err)
}
fmt.Println(entry.URL())
header, err := entry.Header()
if err != nil {
log.Fatal(err)
}
for _, key := range []string{"Status", "Content-Length", "Content-Type"} {
fmt.Printf("%s: %s\n", key, header.Get(key))
}
body, err := entry.Body()
if err != nil {
log.Fatal(err)
}
defer body.Close()
config, err := png.DecodeConfig(body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("PNG image data, %d x %d\n", config.Width, config.Height)
}
Output: https://golang.org/doc/gopher/pkg.png Status: 200 Content-Length: 5409 Content-Type: image/png PNG image data, 83 x 120
Index ¶
- Variables
- type CacheAddr
- func (addr CacheAddr) BlockSize() uint32
- func (addr CacheAddr) FileName() (name string)
- func (addr CacheAddr) FileNumber() uint32
- func (addr CacheAddr) FileType() uint32
- func (addr CacheAddr) Initialized() bool
- func (addr CacheAddr) NumBlocks() uint32
- func (addr CacheAddr) SeparateFile() bool
- func (addr CacheAddr) StartBlock() uint32
- type DiskCache
- type Entry
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBadAddr = errors.New("addr is not initialized")
ErrBadAddr is returned if the addr is not initialized.
var ErrNotFound = errors.New("entry not found")
ErrNotFound is returned when an entry is not found in cache.
Functions ¶
This section is empty.
Types ¶
type CacheAddr ¶
type CacheAddr uint32
CacheAddr defines a storage address for a cache record.
func (CacheAddr) FileNumber ¶
FileNumber returns the file number.
func (CacheAddr) FileType ¶
FileType returns one of these values:
EXTERNAL = 0, RANKINGS = 1, BLOCK_256 = 2, BLOCK_1K = 3, BLOCK_4K = 4, BLOCK_FILES = 5, BLOCK_ENTRIES = 6, BLOCK_EVICTED = 7
func (CacheAddr) Initialized ¶
Initialized returns the initialization state.
func (CacheAddr) SeparateFile ¶
SeparateFile returns true if the cache record is located in a separated file.
func (CacheAddr) StartBlock ¶
StartBlock returns the start block.
type DiskCache ¶
type DiskCache struct {
// contains filtered or unexported fields
}
DiskCache reads the blocks files and maps URL to CacheAddr.
func (DiskCache) GetAddr ¶
GetAddr returns the addr for url. The returned CacheAddr might not be initialized, meaning that the url is unknown.
