You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cache.go 3.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package cache
  2. import (
  3. "os"
  4. "path/filepath"
  5. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  6. "gitlink.org.cn/cloudream/storage/client2/internal/mount/fuse"
  7. )
  8. type CacheEntry interface {
  9. fuse.FsEntry
  10. // 在虚拟文件系统中的路径,即不包含缓存目录的路径
  11. PathComps() []string
  12. // 不再使用本缓存条目
  13. Release()
  14. }
  15. type Cache struct {
  16. cacheDataDir string
  17. cacheMetaDir string
  18. }
  19. func (c *Cache) GetCacheDataPath(comps ...string) string {
  20. comps2 := make([]string, len(comps)+1)
  21. comps2[0] = c.cacheDataDir
  22. copy(comps2[1:], comps)
  23. return filepath.Join(comps2...)
  24. }
  25. func (c *Cache) GetCacheDataPathComps(comps ...string) []string {
  26. comps2 := make([]string, len(comps)+1)
  27. comps2[0] = c.cacheDataDir
  28. copy(comps2[1:], comps)
  29. return comps2
  30. }
  31. func (c *Cache) GetCacheMetaPath(comps ...string) string {
  32. comps2 := make([]string, len(comps)+1)
  33. comps2[0] = c.cacheMetaDir
  34. copy(comps2[1:], comps)
  35. return filepath.Join(comps2...)
  36. }
  37. func (c *Cache) GetCacheMetaPathComps(comps ...string) []string {
  38. comps2 := make([]string, len(comps)+1)
  39. comps2[0] = c.cacheMetaDir
  40. copy(comps2[1:], comps)
  41. return comps2
  42. }
  43. // 加载指定路径的缓存文件或者目录,如果路径不存在,则返回nil。
  44. func (c *Cache) LoadAny(pathComps []string) CacheEntry {
  45. pat := c.GetCacheMetaPath(pathComps...)
  46. info, err := os.Stat(pat)
  47. if err != nil {
  48. // TODO 日志记录
  49. return nil
  50. }
  51. if info.IsDir() {
  52. return newCacheDir(pathComps, info)
  53. }
  54. file, err := loadCacheFile(pathComps, pat)
  55. if err != nil {
  56. // TODO 日志记录
  57. return nil
  58. }
  59. return file
  60. }
  61. // 加载指定缓存文件,如果文件不存在,则根据create参数决定是否创建文件。
  62. //
  63. // 如果create为false,且文件不存在,则返回nil。如果目标位置是一个目录,则也会返回nil。
  64. func (c *Cache) LoadFile(pathComps []string, create bool) *CacheFile {
  65. }
  66. // 加载指定缓存文件,如果文件不存在,则根据obj参数创建缓存文件。
  67. func (c *Cache) LoadOrCreateFile(pathComps []string, obj cdssdk.Object) *CacheFile {
  68. }
  69. // 加载指定缓存目录,如果目录不存在,则根据create参数决定是否创建目录。
  70. //
  71. // 如果create为false,且目录不存在,则返回nil。如果目标位置是一个文件,则也会返回nil。
  72. func (c *Cache) LoadDir(pathComps []string, create bool) *CacheDir {
  73. }
  74. // 加载指定路径下所有的缓存文件或者目录,如果路径不存在,则返回nil。
  75. func (c *Cache) LoadMany(pathComps []string) []CacheEntry {
  76. }
  77. // 删除指定路径的缓存文件或目录。删除目录时如果目录不为空,则会报错。
  78. func (c *Cache) Remove(pathComps []string) error {
  79. }
  80. // 移动指定路径的缓存文件或目录到新的路径。如果目标路径已经存在,则会报错。
  81. //
  82. // 如果移动成功,则返回移动后的缓存文件或目录。如果文件或目录不存在,则返回nil。
  83. func (c *Cache) Move(pathComps []string, newPathComps []string) (CacheEntry, error) {
  84. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。