{"id":26702084,"url":"https://github.com/leoantony72/goswift","last_synced_at":"2025-04-13T11:26:55.170Z","repository":{"id":194744313,"uuid":"691488490","full_name":"leoantony72/goswift","owner":"leoantony72","description":"High-performance, concurrent embedded caching library for Go applications with support for Hash data type, Disk Save and TTL","archived":false,"fork":false,"pushed_at":"2025-01-20T12:56:32.000Z","size":55,"stargazers_count":66,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T02:39:08.884Z","etag":null,"topics":["cache","concurrency","data-structures","database","go","golang","golang-package","library"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leoantony72.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-14T09:28:01.000Z","updated_at":"2025-03-22T14:35:21.000Z","dependencies_parsed_at":"2023-09-27T11:10:14.257Z","dependency_job_id":"2f2d222f-873b-405c-b345-08736ad69bd3","html_url":"https://github.com/leoantony72/goswift","commit_stats":null,"previous_names":["leoantony72/goswift"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoantony72%2Fgoswift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoantony72%2Fgoswift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoantony72%2Fgoswift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoantony72%2Fgoswift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leoantony72","download_url":"https://codeload.github.com/leoantony72/goswift/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248704877,"owners_count":21148444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","concurrency","data-structures","database","go","golang","golang-package","library"],"created_at":"2025-03-27T02:33:30.430Z","updated_at":"2025-04-13T11:26:55.148Z","avatar_url":"https://github.com/leoantony72.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoSwift - Embedded cache for golang\n\nHigh-performance, concurrent embedded caching library for Go applications with support for Hash data type\n\n## Features\n\n- Set \u0026 Get command\n- Del command\n- Update command\n- Exists command\n- Support for TTL\n- Support for Disk Save(Snapshots)\n- Support Hash Data type Hset, Hget, HgetAll, HMset\n- Safe Locking\n\n## Installation\n\n```shell\ngo mod init github.com/my/repo\n```\n\nThen install goswift:\n\n```shell\ngo get github.com/leoantony72/goswift\n```\n\n## Quickstart\n\n```go\n\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/leoantony72/goswift\"\n)\n\nfunc main(){\n    cache := goswift.NewCache()\n\n    // Value 0 indicates no expiry\n    cache.Set(\"key\", \"value\", 0)\n\n    val, err := cache.Get(\"key\")\n    if err !=nil{\n        fmt.Println(err)\n        return\n    }\n    fmt.Println(\"key\", val)\n}\n\n```\n\n## Disk Save\n\n### Snapshot\n\n```go\nopt := goswift.CacheOptions{\n\t\tEnableSnapshots:  true,\n\t\tSnapshotInterval: time.Second*5,\n\t}\nc := goswift.NewCache(opt)\n```\n\n\u003e **_NOTE:_** If the **EnableSnapshot** is **false**, Data saved in the file will not imported\n\nThis will take a snapshot of the Data Every 5sec and saves it into a **_Snapshot.data_** file. By default Snapshots are disabled and if the SnapshotInterval is not provided default value is **5seconds**.\n\n\u003e **_NOTE:_** Don't delete the **_Snapshot.data_** File \u003cbr\u003e\n\n## Error Handling\n\n```go\nconst (\n\tErrKeyNotFound   = \"key does not Exists\"\n\tErrFieldNotFound = \"field does not Exists\"\n\tErrNotHashvalue  = \"not a Hash value/table\"\n\tErrHmsetDataType = \"invalid data type, Expected Struct/Map\"\n)\n```\n\nThese are the common Errors that may occur while writing the code. These Varible provide you a clear and easy **Error** comparison method to determine errors.\n\n```go\ndata,err := cache.Get(\"key\")\nif err != nil {\n\tif err.Error() == goswift.ErrKeyNotFound {\n        //do something\n}\n}\n```\n\n## Usage\n\n```go\n// Set Value with Expiry\n// @Set(key string, val interface{}, exp int)\n// Here expiry is set to 1sec\ncache.Set(\"key\",\"value\",1000)\n\n\n// Get Value with key\n// @Get(key string) (interface{}, error)\nval,err := cache.Get(\"key\")\nif err != nil{\n    fmt.Println(err)\n    return\n}\n\n\n// Update value\n// @Update(key string, val interface{}) error\nerr = cache.Update(\"key\",\"value2\")\nif err != nil{\n    fmt.Println(err)\n    return\n}\n\n\n// Delete command\n// @Del(key string)\ncache.Del(\"key\")\n\n\n// Hset command\n// @Hset(key, field string, value interface{}, exp int)\n// in this case the \"key\" expires in 1sec\ncache.Hset(\"key\",\"name\",\"value\",1000)\ncache.Hset(\"key\",\"age\",18,1000)\n\n\n// HMset command\n// @HMset(key string, d interface{}, exp int) error\n// Set a Hash by passing a Struct/Map\n// ---by passing a struct---\ntype Person struct{\n    Name  string\n    Age   int\n    Place string\n}\n\nperson1 := \u0026Person{Name:\"bob\",Age:18,Place:\"NYC\"}\nerr = cache.HMset(\"key\",person1)\nif err != nil{\n    fmt.Println(err)\n    return\n}\n\n// ---by passing a map---\nperson2 := map[string]interface{Name:\"john\",Age:18,Place:\"NYC\"}\nerr = cache.HMset(\"key\",person2)\nif err != nil{\n    fmt.Println(err)\n    return\n}\n\n\n// Hget command\n// @HGet(key, field string) (interface{}, error)\n// get individual fields in Hash\ndata,err := cache.HGet(\"key\",\"field\")\nif err != nil{\n    fmt.Println(err)\n    return\n}\nfmt.Println(data)\n\n// HgetAll command\n// @HGetAll(key string) (map[string]interface{}, error)\n// gets all the fields with value in a hash key\n// retuns a map[string]interface{}\ndata,err = cache.HGetAll(\"key\")\nif err != nil{\n    fmt.Println(err)\n    return\n}\n\n\n// Exist command\n// @Exists(key string) bool\n// Check if the key exists\nvalue = cache.Exists(\"key\")\nfmt.Println(value)\n\n\n\n// AllData command\n// @AllData() (map[string]interface{}, int)\n// returns all the data in the cache with keys, also with no.of keys present\n// returns the value as a map[strirng]interface{}\n// !It does not return the expiry time of the key\ndata,counter := cache.AllData()\nfmt.Println(data,counter)\n\n```\n\n## Run the Test\n\n```go\ngo test ./...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleoantony72%2Fgoswift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleoantony72%2Fgoswift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleoantony72%2Fgoswift/lists"}