func (c *Cache) SaveToFileConcurrent(filePath string, concurrency int) error {
	// Create dir if it doesn't exist.
	dir := filepath.Dir(filePath)
	if _, err := os.Stat(dir); err != nil {
		if !os.IsNotExist(err) {
			return fmt.Errorf("cannot stat %q: %s", dir, err)
		}
		if err := os.MkdirAll(dir, 0755); err != nil {
			return fmt.Errorf("cannot create dir %q: %s", dir, err)
		}
	}

	// Save cache data into a temporary directory.
	tmpDir, err := ioutil.TempDir(dir, "fastcache.tmp.")
	if err != nil {
		return fmt.Errorf("cannot create temporary dir inside %q: %s", dir, err)
	}
	defer func() {
		if tmpDir != "" {
			_ = os.RemoveAll(tmpDir)
		}
	}()
	gomaxprocs := runtime.GOMAXPROCS(-1)
	if concurrency <= 0 || concurrency > gomaxprocs {
		concurrency = gomaxprocs
	}
	if err := c.save(tmpDir, concurrency); err != nil {
		return fmt.Errorf("cannot save cache data to temporary dir %q: %s", tmpDir, err)
	}

	// Remove old filePath contents, since os.Rename may return
	// error if filePath dir exists.
	if err := os.RemoveAll(filePath); err != nil {
		return fmt.Errorf("cannot remove old contents at %q: %s", filePath, err)
	}
	if err := os.Rename(tmpDir, filePath); err != nil {
		return fmt.Errorf("cannot move temporary dir %q to %q: %s", tmpDir, filePath, err)
	}
	tmpDir = ""
	return nil
}
// SaveToFileConcurrent saves cache data to the given filePath using concurrency
// CPU cores.
//
// SaveToFileConcurrent may be called concurrently with other operations
// on the cache.
//
// The saved data may be loaded with LoadFromFile*.
//
// See also SaveToFile.
SaveToFileConcurrent saves cache data to the given filePath using concurrency
CPU cores.

SaveToFileConcurrent may be called concurrently with other operations
on the cache.

The saved data may be loaded with LoadFromFile*.

See also SaveToFile.
// SaveToFileConcurrent saves cache data to the given filePath using concurrency // CPU cores . // // SaveToFileConcurrent may be called concurrently with other operations // on the cache . // // The saved data may be loaded with LoadFromFile * . // // See also SaveToFile .
func (c *Cache) SaveToFileConcurrent(filePath string, concurrency int) error {
	dir := filepath.Dir(filePath)
	if _, err := os.Stat(dir); err != nil {
		if !os.IsNotExist(err) {
			return fmt.Errorf("cannot stat %q: %s", dir, err)
		}
		if err := os.MkdirAll(dir, 0755); err != nil {
			return fmt.Errorf("cannot create dir %q: %s", dir, err)
		}
	}
	tmpDir, err := ioutil.TempDir(dir, "fastcache.tmp.")
	if err != nil {
		return fmt.Errorf("cannot create temporary dir inside %q: %s", dir, err)
	}
	defer func() {
		if tmpDir != "" {
			_ = os.RemoveAll(tmpDir)
		}
	}()
	gomaxprocs := runtime.GOMAXPROCS(-1)
	if concurrency <= 0 || concurrency > gomaxprocs {
		concurrency = gomaxprocs
	}
	if err := c.save(tmpDir, concurrency); err != nil {
		return fmt.Errorf("cannot save cache data to temporary dir %q: %s", tmpDir, err)
	}
	if err := os.RemoveAll(filePath); err != nil {
		return fmt.Errorf("cannot remove old contents at %q: %s", filePath, err)
	}
	if err := os.Rename(tmpDir, filePath); err != nil {
		return fmt.Errorf("cannot move temporary dir %q to %q: %s", tmpDir, filePath, err)
	}
	tmpDir = ""
	return nil
}
func ( c * Cache ) SaveToFileConcurrent ( filePath string , concurrency int ) error { dir := filepath . Dir ( filePath ) if _ , err := os . Stat ( dir ) ; err != nil { if ! os . IsNotExist ( err ) { return fmt . Errorf ( " " , dir , err ) } if err := os . MkdirAll ( dir , 0755 ) ; err != nil { return fmt . Errorf ( " " , dir , err ) } } tmpDir , err := ioutil . TempDir ( dir , " " ) if err != nil { return fmt . Errorf ( " " , dir , err ) } defer func ( ) { if tmpDir != " " { _ = os . RemoveAll ( tmpDir ) } } ( ) gomaxprocs := runtime . GOMAXPROCS ( - 1 ) if concurrency <= 0 || concurrency > gomaxprocs { concurrency = gomaxprocs } if err := c . save ( tmpDir , concurrency ) ; err != nil { return fmt . Errorf ( " " , tmpDir , err ) } if err := os . RemoveAll ( filePath ) ; err != nil { return fmt . Errorf ( " " , filePath , err ) } if err := os . Rename ( tmpDir , filePath ) ; err != nil { return fmt . Errorf ( " " , tmpDir , filePath , err ) } tmpDir = " " return nil }
SaveToFileConcurrent saves cache data to the given filePath using concurrency
CPU cores.
SaveToFileConcurrent saves cache data to the given filePath using concurrency CPU cores .
// Create dir if it doesn't exist. // Save cache data into a temporary directory. // Remove old filePath contents, since os.Rename may return // error if filePath dir exists.