-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
google cloud storage cachestore (#18)
* MVP: google cloud storage cachestore * MVP: google cloud storage cachestore - handle does not exist * MVP: google cloud storage cachestore - ClearAll * MVP: google cloud storage cachestore - small refactor to match other cachestore impl * MVP: google cloud storage cachestore - add example * MVP: google cloud storage cachestore - unit tests * MVP: google cloud storage cachestore - unit tests missing error check * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage_test.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * refactor + apply review remarks * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * apply review remarks * replace bucket name * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> * Update gcstorage/gcstorage.go Co-authored-by: David Sedláček <[email protected]> --------- Co-authored-by: David Sedláček <[email protected]>
- Loading branch information
1 parent
509f7d6
commit 75090a8
Showing
8 changed files
with
843 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/goware/cachestore" | ||
"github.com/goware/cachestore/cachestorectl" | ||
"github.com/goware/cachestore/gcstorage" | ||
) | ||
|
||
func main() { | ||
cfg := &gcstorage.Config{ | ||
Bucket: "test-bucket", | ||
KeyPrefix: "test/", | ||
} | ||
|
||
backend := gcstorage.Backend(cfg) //, cachestore.WithDefaultKeyExpiry(1*time.Second)) | ||
|
||
store, err := cachestorectl.Open[string](backend, cachestore.WithDefaultKeyExpiry(30*time.Second)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
// Set | ||
for i := 0; i < 10; i++ { | ||
err = store.Set(ctx, fmt.Sprintf("foo:%d", i), fmt.Sprintf("value-%d", i)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
store.SetEx(ctx, "foo:999", "value-999", 10*time.Minute) | ||
|
||
// Exists | ||
ok, err := store.Exists(ctx, "foo:9") | ||
if err != nil { | ||
panic(err) | ||
} | ||
if !ok { | ||
panic("unexpected") | ||
} | ||
fmt.Println("=> exists(foo:9) =", ok) | ||
|
||
// Get | ||
v, ok, err := store.Get(ctx, "foo:9") | ||
if err != nil { | ||
panic(err) | ||
} | ||
if !ok { | ||
panic("unexpected") | ||
} | ||
fmt.Println("=> get(foo:9) =", v) | ||
|
||
time.Sleep(30 * time.Second) | ||
|
||
// should expire based on rule above | ||
ok, err = store.Exists(ctx, "foo:9") | ||
if err != nil { | ||
panic(err) | ||
} | ||
if ok { | ||
panic("unexpected") | ||
} | ||
fmt.Println("=> exists(foo:9) =", ok) | ||
|
||
v, ok, err = store.Get(ctx, "foo:9") | ||
if err != nil { | ||
panic(err) | ||
} | ||
if ok { | ||
panic("unexpected") | ||
} | ||
fmt.Println("=> get(foo:9) =", v) | ||
|
||
// should still have | ||
v, ok, err = store.Get(ctx, "foo:999") | ||
if err != nil { | ||
panic(err) | ||
} | ||
if !ok { | ||
panic("unexpected") | ||
} | ||
fmt.Println("=> get(foo:999) =", v) | ||
|
||
// DeletePrefix | ||
err = store.DeletePrefix(ctx, "foo:") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// be gone | ||
_, ok, _ = store.Get(ctx, "foo:999") | ||
if ok { | ||
panic("unexpected") | ||
} | ||
|
||
fmt.Println("done.") | ||
fmt.Println("") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package gcstorage | ||
|
||
import ( | ||
"github.com/goware/cachestore" | ||
"golang.org/x/oauth2/google" | ||
) | ||
|
||
type Config struct { | ||
cachestore.StoreOptions | ||
|
||
Credentials *google.Credentials | ||
|
||
Bucket string | ||
KeyPrefix string | ||
} | ||
|
||
func (c *Config) Apply(options *cachestore.StoreOptions) { | ||
c.StoreOptions.Apply(options) | ||
} |
Oops, something went wrong.