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