Documentation
¶
Overview ¶
Package cache は key-value 型の簡易 DB です.
New() でインスタンスが作成されると、テンポラリ・ディレクトリにキャッシュ用のディレクトリを作成します。 主に "Set(<翻訳前テキスト>, <翻訳後テキスト>)" のように、翻訳結果をキャッシュするのに使われます。 デフォルトで共通のキャッシュ・ディレクトリを利用します。異なるキャッシュにしたい場合は任意のキャッシュ ID を指定します。
myCache := cache.New("myCache")
主なメソッド
Set(key, value) ... キャッシュの作成・更新をします Get(key) ... キャッシュから値を取得します。 ClearAll() ... キャッシュ・ディレクトリを削除します。
Index ¶
- Constants
- type TCache
- func (c *TCache) ClearAll()
- func (c *TCache) CloseDB()
- func (c *TCache) Get(key string) (string, error)
- func (c *TCache) GetPathDirCache() string
- func (c *TCache) GetValueInByte(keyHashed []byte) ([]byte, error)
- func (c *TCache) OpenDB() (err error)
- func (c *TCache) Set(key string, value string) (err error)
Examples ¶
Constants ¶
View Source
const (
NameDirCacheDefault = "QiiTrans"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TCache ¶
type TCache struct {
NameDirCache string
PathDirTemp string
// contains filtered or unexported fields
}
func New ¶
New は TCache の新規オブジェクトのポインタを返します. デフォルトで共通のキャッシュを利用します。各々異なるキャッシュにしたい場合は、引数に ID を指定します.
Example ¶
package main
import (
"fmt"
"github.com/Qithub-BOT/QiiTrans/src/cache"
)
func main() {
// 汎用のキャッシュにしたくない場合は ID を指定する。この場合は "my sample DB".
c := cache.New("my sample DB")
// 終了時にキャッシュを削除したい場合は defer で ClearAll する
defer c.ClearAll()
phraseOriginal := "Hello, world!"
phraseTranslated := "世界よ、こんにちは!"
// Set でキャッシュに登録
_ = c.Set(phraseOriginal, phraseTranslated)
// Get でキャッシュから取得
result, _ := c.Get(phraseOriginal)
fmt.Println(result)
}
Output: 世界よ、こんにちは!
func (*TCache) GetPathDirCache ¶
GetPathDirCache は現在のキャッシュ先のディレクトリを返します.
func (*TCache) GetValueInByte ¶
GetValueInByte はバイトデータにハッシュ化された keyHashed キーを使ってキャッシュを探索しバイトデータで返します.
Click to show internal directories.
Click to hide internal directories.