-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
627 additions
and
0 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
* + ansi | ||
* + cache/memory | ||
* + cache/fs | ||
* + color | ||
* + cron | ||
* + csv | ||
|
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,128 @@ | ||
package fs | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
// // | ||
// Copyright (c) 2024 ESSENTIAL KAOS // | ||
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // | ||
// // | ||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
func ExampleNew() { | ||
cache, _ := New(Config{ | ||
Dir: "/path/to/cache", | ||
DefaultExpiration: time.Minute, | ||
CleanupInterval: time.Minute, | ||
}) | ||
|
||
cache.Set("test", "ABCD") | ||
|
||
fmt.Println(cache.Get("test")) | ||
} | ||
|
||
func ExampleCache_Set() { | ||
cache, _ := New(Config{ | ||
Dir: "/path/to/cache", | ||
DefaultExpiration: time.Minute, | ||
CleanupInterval: time.Minute, | ||
}) | ||
|
||
cache.Set("test", "ABCD") | ||
cache.Set("test", "ABCD", 15*time.Minute) | ||
|
||
fmt.Println(cache.Get("test")) | ||
} | ||
|
||
func ExampleCache_Has() { | ||
cache, _ := New(Config{ | ||
Dir: "/path/to/cache", | ||
DefaultExpiration: time.Minute, | ||
CleanupInterval: time.Minute, | ||
}) | ||
|
||
cache.Set("test", "ABCD") | ||
|
||
fmt.Println(cache.Has("test")) | ||
} | ||
|
||
func ExampleCache_Get() { | ||
cache, _ := New(Config{ | ||
Dir: "/path/to/cache", | ||
DefaultExpiration: time.Minute, | ||
CleanupInterval: time.Minute, | ||
}) | ||
|
||
cache.Set("test", "ABCD") | ||
|
||
fmt.Println(cache.Get("test")) | ||
} | ||
|
||
func ExampleCache_Size() { | ||
cache, _ := New(Config{ | ||
Dir: "/path/to/cache", | ||
DefaultExpiration: time.Minute, | ||
CleanupInterval: time.Minute, | ||
}) | ||
|
||
cache.Set("test", "ABCD") | ||
|
||
fmt.Println(cache.Size()) | ||
} | ||
|
||
func ExampleCache_Expired() { | ||
cache, _ := New(Config{ | ||
Dir: "/path/to/cache", | ||
DefaultExpiration: time.Minute, | ||
CleanupInterval: time.Minute, | ||
}) | ||
|
||
cache.Set("test", "ABCD") | ||
|
||
fmt.Println(cache.Expired()) | ||
} | ||
|
||
func ExampleCache_GetWithExpiration() { | ||
cache, _ := New(Config{ | ||
Dir: "/path/to/cache", | ||
DefaultExpiration: time.Minute, | ||
CleanupInterval: time.Minute, | ||
}) | ||
|
||
cache.Set("test", "ABCD") | ||
|
||
item, exp := cache.GetWithExpiration("test") | ||
|
||
fmt.Println(item, exp.String()) | ||
} | ||
|
||
func ExampleCache_Delete() { | ||
cache, _ := New(Config{ | ||
Dir: "/path/to/cache", | ||
DefaultExpiration: time.Minute, | ||
CleanupInterval: time.Minute, | ||
}) | ||
|
||
cache.Set("test", "ABCD") | ||
cache.Delete("test") | ||
|
||
fmt.Println(cache.Get("test")) | ||
} | ||
|
||
func ExampleCache_Flush() { | ||
cache, _ := New(Config{ | ||
Dir: "/path/to/cache", | ||
DefaultExpiration: time.Minute, | ||
CleanupInterval: time.Minute, | ||
}) | ||
|
||
cache.Set("test", "ABCD") | ||
cache.Flush() | ||
|
||
fmt.Println(cache.Get("test")) | ||
} |
Oops, something went wrong.