func Store(key string, lifetime time.Duration, data interface{}) State {
	err := ensureDirectory()
	if err != nil {
		return CacheNotAvailable
	}

	key = path.Join(cachePath(), key)

	file, err := os.OpenFile(key, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		return CacheNotAvailable
	}
	defer file.Close()

	encoder := json.NewEncoder(file)
	if encoder == nil {
		return CacheNotAvailable
	}

	var contents Cacheable
	contents.Expires.Time = time.Now().Add(lifetime)
	contents.Contents = data
	err = encoder.Encode(&contents)
	if err != nil {
		return CacheNotAvailable
	}

	return CacheFound
}
// Store stores the given data interface as a JSON file with a given expiration time
// under the given key.
Store stores the given data interface as a JSON file with a given expiration time
under the given key.
// Store stores the given data interface as a JSON file with a given expiration time // under the given key .
func Store(key string, lifetime time.Duration, data interface{}) State {
	err := ensureDirectory()
	if err != nil {
		return CacheNotAvailable
	}
	key = path.Join(cachePath(), key)
	file, err := os.OpenFile(key, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		return CacheNotAvailable
	}
	defer file.Close()
	encoder := json.NewEncoder(file)
	if encoder == nil {
		return CacheNotAvailable
	}
	var contents Cacheable
	contents.Expires.Time = time.Now().Add(lifetime)
	contents.Contents = data
	err = encoder.Encode(&contents)
	if err != nil {
		return CacheNotAvailable
	}
	return CacheFound
}
func Store ( key string , lifetime time . Duration , data interface { } ) State { err := ensureDirectory ( ) if err != nil { return CacheNotAvailable } key = path . Join ( cachePath ( ) , key ) file , err := os . OpenFile ( key , os . O_RDWR | os . O_CREATE | os . O_TRUNC , 0600 ) if err != nil { return CacheNotAvailable } defer file . Close ( ) encoder := json . NewEncoder ( file ) if encoder == nil { return CacheNotAvailable } var contents Cacheable contents . Expires . Time = time . Now ( ) . Add ( lifetime ) contents . Contents = data err = encoder . Encode ( & contents ) if err != nil { return CacheNotAvailable } return CacheFound }
Store stores the given data interface as a JSON file with a given expiration time
under the given key.
Store stores the given data interface as a JSON file with a given expiration time under the given key .