GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — sqlcache/doc.go at master · pushmarket/sqlcache Expand file tree/ Copy pathdoc.goMore file actions 47 lines (37 loc) · 1.27 KB / Copy pathdoc.goFile metadata and controls47 lines (37 loc) · 1.27 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 /* Package sqlcache provides an experimental caching middleware for database/sql users. This liberates your Go program from maintaining imperative code that implements the cache-aside pattern. Your program will perceive the database client/driver as a read-through cache. Usage: import ( "database/sql" redis "github.com/go-redis/redis/v7" "github.com/pushmarket/sqlcache" "github.com/jackc/pgx/v4/stdlib" ) func main() { ... rc := redis.NewUniversalClient(&redis.UniversalOptions{ Addrs: []string{"127.0.0.1:6379"}, }) // create a sqlcache.Interceptor instance with the desired backend interceptor, err := sqlcache.NewInterceptor(&sqlcache.Config{ Cache: sqlcache.NewRedis(rc, "sqc"), }) ... // wrap pgx driver with the interceptor and register it sql.Register("pgx-with-cache", interceptor.Driver(stdlib.GetDefaultDriver())) // open the database using the wrapped driver db, err := sql.Open("pgx-with-cache", dsn) ... } Caching is controlled using cache attributes which are SQL comments starting with `@cache-` prefix. Only queries with cache attributes are cached. Example query: rows, err := db.QueryContext(context.TODO(), ` -- @cache-ttl 30 -- @cache-max-rows 10 SELECT name, pages FROM books WHERE pages > $1`, 100) */ package sqlcache |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |