diff --git a/app/multitenant/memcache_client.go b/app/multitenant/memcache_client.go index 9809f950c..ee8e0e07e 100644 --- a/app/multitenant/memcache_client.go +++ b/app/multitenant/memcache_client.go @@ -2,6 +2,7 @@ package multitenant import ( "bytes" + "compress/gzip" "fmt" "net" "sort" @@ -202,6 +203,13 @@ func (c *MemcacheClient) FetchReports(keys []string) (map[string]report.Report, return reports, missing, nil } +// StoreReport serializes and stores a report. +func (c *MemcacheClient) StoreReport(key string, report *report.Report) error { + var buf bytes.Buffer + report.WriteBinary(&buf, gzip.BestCompression) + return c.StoreBytes(key, buf.Bytes()) +} + // StoreBytes stores a report, expecting the report to be serialized already. func (c *MemcacheClient) StoreBytes(key string, content []byte) error { return instrument.TimeRequestHistogramStatus("Put", memcacheRequestDuration, memcacheStatusCode, func() error { diff --git a/app/multitenant/s3_client.go b/app/multitenant/s3_client.go index 94deef5f3..6d90bda74 100644 --- a/app/multitenant/s3_client.go +++ b/app/multitenant/s3_client.go @@ -2,6 +2,7 @@ package multitenant import ( "bytes" + "compress/gzip" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" @@ -84,6 +85,13 @@ func (store *S3Store) fetchReport(key string) (*report.Report, error) { return report.MakeFromBinary(resp.Body) } +// StoreReport serializes and stores a report. +func (store *S3Store) StoreReport(key string, report *report.Report) error { + var buf bytes.Buffer + report.WriteBinary(&buf, gzip.BestCompression) + return store.StoreBytes(key, buf.Bytes()) +} + // StoreBytes stores a report in S3, expecting the report to be serialized // already. func (store *S3Store) StoreBytes(key string, content []byte) error {