@@ -10,8 +10,13 @@ import (
1010 "github.com/ncruces/go-sqlite3/vfs"
1111)
1212
13- // The default poll interval.
14- const DefaultPollInterval = 1 * time .Second
13+ const (
14+ // The default poll interval.
15+ DefaultPollInterval = 1 * time .Second
16+
17+ // The default cache size: 10 MiB.
18+ DefaultCacheSize = 10 * 1024 * 1024
19+ )
1520
1621func init () {
1722 vfs .Register ("litestream" , liteVFS {})
@@ -27,11 +32,18 @@ var (
2732type ReplicaOptions struct {
2833 // Where to log error messages. May be nil.
2934 Logger * slog.Logger
30- // Minimum compaction level to track.
31- MinLevel int
32- // Replica poll interval. Must be less than the compaction interval
35+
36+ // Replica poll interval.
37+ // Should be less than the compaction interval
3338 // used by the replica at MinLevel+1.
3439 PollInterval time.Duration
40+
41+ // Minimum compaction level to track.
42+ MinLevel int
43+
44+ // CacheSize is the maximum size of the page cache in bytes.
45+ // Zero means DefaultCacheSize, negative disables caching.
46+ CacheSize int
3547}
3648
3749// NewReplica creates a read-replica from a Litestream client.
@@ -44,12 +56,16 @@ func NewReplica(name string, client litestream.ReplicaClient, options ReplicaOpt
4456 if options .PollInterval <= 0 {
4557 options .PollInterval = DefaultPollInterval
4658 }
59+ if options .CacheSize == 0 {
60+ options .CacheSize = DefaultCacheSize
61+ }
4762
4863 liteMtx .Lock ()
4964 defer liteMtx .Unlock ()
5065 liteDBs [name ] = & liteDB {
5166 client : client ,
52- opts : & options ,
67+ opts : options ,
68+ cache : pageCache {size : options .CacheSize },
5369 }
5470}
5571
0 commit comments