diff --git a/storage_versioned_docs/version-scylladb_v0.x.x/README.md b/storage_versioned_docs/version-scylladb_v0.x.x/README.md index 0e35501cc47..573df7fcb45 100644 --- a/storage_versioned_docs/version-scylladb_v0.x.x/README.md +++ b/storage_versioned_docs/version-scylladb_v0.x.x/README.md @@ -64,6 +64,7 @@ type Storage interface { - [MongoDB](./mongodb/README.md) - [MSSQL](./mssql/README.md) - [MySQL](./mysql/README.md) +- [NATS](./nats/README.md) - [Pebble](./pebble/README.md) - [Postgres](./postgres/README.md) - [Redis](./redis/README.md) @@ -71,4 +72,3 @@ type Storage interface { - [S3](./s3/README.md) - [ScyllaDB](./scylladb/README.md) - [SQLite3](./sqlite3/README.md) - diff --git a/storage_versioned_docs/version-scylladb_v0.x.x/coherence/README.md b/storage_versioned_docs/version-scylladb_v0.x.x/coherence/README.md index 2fe828c6b3d..f4d12aaeb7c 100644 --- a/storage_versioned_docs/version-scylladb_v0.x.x/coherence/README.md +++ b/storage_versioned_docs/version-scylladb_v0.x.x/coherence/README.md @@ -35,7 +35,7 @@ necessary for the client to operate correctly. To start a Coherence cluster using Docker, issue the following: ```bash -docker run -d -p 1408:1408 ghcr.io/oracle/coherence-ce:22.06.5 +docker run -d -p 1408:1408 ghcr.io/oracle/coherence-ce:22.06.7 ``` See the documentation [here](https://pkg.go.dev/github.com/oracle/coherence-go-client/coherence#hdr-Obtaining_a_Session) on connection options @@ -52,9 +52,10 @@ You can use the following possibilities to create a storage: // Initialize default config, to connect to localhost:1408 using plain text store, err := coherence.New() -// Initialize custom config to connect to a different host/port and use plaint ext. +// Initialize custom config to connect to a different host/port and use plain text and expiry of 5 minutes. store, err := coherence.New(coherence.Config{ Address: "my-host:myport", + Expiration: time.Duration(300) * time.Second, // 5 minutes }) // Initialize to connect with TLS enabled with your own tls.Config @@ -66,13 +67,38 @@ store, err := coherence.New(coherence.Config{ }) ``` -> Note: If you create two stores using `coherence.New()` they will effectivity be idential. +> Note: If you create two stores using `coherence.New()` they will effectivity be identical. > If you wish to have two separate stores, then you can use: > ```go > store1, err := coherence.New(Config{ScopeName: "scope1"}) > store2, err := coherence.New(Config{ScopeName: "scope2"}) > ``` +**Near Caches** + +The latest version of the Coherence Go client introduces near cache support +to cache frequently accessed data in the Go client to avoid sending requests across the network. + +This is particularly useful if you are using sticky sessions via a LBR as this will cache +the session in the Go process and the `Get()` operations will be much quicker. + +When the session is expired on the server it will automatically be removed from the near cache. + +To enable this for you session, you can set the `NearCacheTimeout` to a duration less than the expiry. + +```go +// Initialize default config, to connect to localhost:1408 using plain text +store, err := coherence.New() + +// Use plain text with default expiry of 5 minutes, and a near cache expiry of 2 minutes +store, err := coherence.New(coherence.Config{ + Address: "my-host:myport", + Expiration: time.Duration(300) * time.Second, // 5 minutes + NearCacheTimeout: time.Duration(120) * time.Second, // 2 minutes +}) +``` +> Note: You must ensure your near cache timeout is less that the session timeout. + ### Config ```go @@ -92,6 +118,11 @@ type Config struct { // TLSConfig specifies tls.Config to use when connecting, if nil then plain text is used TLSConfig *tls.Config + + // NearCacheTimeout defines the timeout for a near cache. Is this is set, then a near cache + // with the timeout is created. Note: this must be less than the session timeout or any timeout you specify + // when using Set(). + NearCacheTimeout time.Duration } ``` @@ -99,8 +130,9 @@ type Config struct { ```go var DefaultConfig = Config{ Address: "localhost:1408", - Timeout: time.Duration(30) * time.Millisecond, + Timeout: time.Duration(120) * time.Seconds, ScopeName: defaultScopeName, Reset: false, + NearCacheTimeout: time.Duration(60) * time.Seconds, } ``` diff --git a/storage_versioned_docs/version-scylladb_v0.x.x/nats/README.md b/storage_versioned_docs/version-scylladb_v0.x.x/nats/README.md new file mode 100644 index 00000000000..8955fd56ea4 --- /dev/null +++ b/storage_versioned_docs/version-scylladb_v0.x.x/nats/README.md @@ -0,0 +1,116 @@ +--- +id: nats +title: Nats +--- + + +![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=nats*) +[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord) +![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-nats.yml?label=Tests) +![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security) +![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter) + +A NATS Key/Value storage driver. + +**Note: Requires Go 1.20 and above** + +### Table of Contents + +- [Signatures](#signatures) +- [Installation](#installation) +- [Examples](#examples) +- [Config](#config) +- [Default Config](#default-config) + +### Signatures + +```go +func New(config ...Config) Storage +func (s *Storage) Get(key string) ([]byte, error) +func (s *Storage) Set(key string, val []byte, exp time.Duration) error +func (s *Storage) Delete(key string) error +func (s *Storage) Reset() error +func (s *Storage) Close() error +func (s *Storage) Conn() (*nats.Conn, jetstream.KeyValue) +func (s *Storage) Keys() ([]string, error) +``` + +### Installation + +[NATS Key/Value Store](https://docs.nats.io/nats-concepts/jetstream/key-value-store) driver is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: + +```bash +go mod init github.com// +``` + +And then install the nats implementation: + +```bash +go get github.com/gofiber/storage/nats +``` + +### Examples + +Import the storage package. + +```go +import "github.com/gofiber/storage/nats" +``` + +You can use the following possibilities to create a storage: + +```go +// Initialize default config +store := nats.New() + +// Initialize custom config +store := nats.New(Config{ + URLs: "nats://127.0.0.1:4443", + NatsOptions: []nats.Option{ + nats.MaxReconnects(2), + // Enable TLS by specifying RootCAs + nats.RootCAs("./testdata/certs/ca.pem"), + }, + KeyValueConfig: jetstream.KeyValueConfig{ + Bucket: "test", + Storage: jetstream.MemoryStorage, + }, +}) +``` + +### Config + +```go +type Config struct { + // Nats URLs, default "nats://127.0.0.1:4222". Can be comma separated list for multiple servers + URLs string + // Nats connection options. See nats_test.go for an example of how to use this. + NatsOptions []nats.Option + // Nats connection name + ClientName string + // Nats context + Context context.Context + // Nats key value config + KeyValueConfig jetstream.KeyValueConfig + // Logger. Using Fiber AllLogger interface for adapting the various log libraries. + Logger log.AllLogger + // Use the Logger for nats events, default: false + Verbose bool + // Wait for connection to be established, default: 100ms + WaitForConnection time.Duration +} +``` + +### Default Config + +```go +var ConfigDefault = Config{ + URLs: nats.DefaultURL, + Context: context.Background(), + ClientName: "fiber_storage", + KeyValueConfig: jetstream.KeyValueConfig{ + Bucket: "fiber_storage", + }, + WaitForConnection: 100 * time.Millisecond, +} +``` diff --git a/storage_versioned_docs/version-scylladb_v0.x.x/postgres/README.md b/storage_versioned_docs/version-scylladb_v0.x.x/postgres/README.md index 4e7f6091ed9..04cbe4ce2a9 100644 --- a/storage_versioned_docs/version-scylladb_v0.x.x/postgres/README.md +++ b/storage_versioned_docs/version-scylladb_v0.x.x/postgres/README.md @@ -53,7 +53,7 @@ store := postgres.New() // Initialize custom config store := postgres.New(postgres.Config{ - Db: dbPool, + DB: dbPool, Table: "fiber_storage", Reset: false, GCInterval: 10 * time.Second, diff --git a/storage_versioned_docs/version-scylladb_v0.x.x/s3/README.md b/storage_versioned_docs/version-scylladb_v0.x.x/s3/README.md index 21a7280e7f4..7fa708f0e0a 100644 --- a/storage_versioned_docs/version-scylladb_v0.x.x/s3/README.md +++ b/storage_versioned_docs/version-scylladb_v0.x.x/s3/README.md @@ -33,7 +33,7 @@ func (s *Storage) Close() error func (s *Storage) Conn() *s3.Client // Additional useful methods. -func (s *Storage) CreateBucker(bucket string) error +func (s *Storage) CreateBucket(bucket string) error func (s *Storage) DeleteBucket(bucket string) error func (s *Storage) SetWithChecksum(key string, val []byte, checksum map[types.ChecksumAlgorithm][]byte) error ```