Repository: dragonflyoss/Dragonfly2
Pull request #1618 (2022-08-31 11:04:23)

refactor: dfpath for certify cache dir
Signed-off-by: Gaius <gaius.qi@gmail.com>

<!--- Provide a general summary of your changes in the Title above -->

## Description
- Refactor certify cache dir.
<!--- Describe your changes in detail -->

## Related Issue

<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

## Screenshots (if appropriate)

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation Update (if none of the other choices apply)

## Checklist

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
- [ ] I have added tests to cover my changes.



Patch:
diff --git a/client/config/dynconfig_manager.go b/client/config/dynconfig_manager.go
index 053eaec8..c97a8ec4 100644
--- a/client/config/dynconfig_manager.go
+++ b/client/config/dynconfig_manager.go
@@ -37,7 +37,7 @@ import (
 )
 
 // Daemon cache file name.
-var cacheFileName = "daemon_dynconfig"
+var cacheFileName = "daemon"
 
 type dynconfigManager struct {
 	internaldynconfig.Dynconfig
diff --git a/client/config/peerhost.go b/client/config/peerhost.go
index 8d9d3a27..1b3fe2dd 100644
--- a/client/config/peerhost.go
+++ b/client/config/peerhost.go
@@ -39,7 +39,7 @@ import (
 	logger "d7y.io/dragonfly/v2/internal/dflog"
 	"d7y.io/dragonfly/v2/pkg/dfnet"
 	netip "d7y.io/dragonfly/v2/pkg/net/ip"
-	"d7y.io/dragonfly/v2/pkg/serialize"
+	"d7y.io/dragonfly/v2/pkg/types"
 	"d7y.io/dragonfly/v2/pkg/unit"
 )
 
@@ -178,7 +178,7 @@ type GlobalSecurityOption struct {
 	// if AutoIssueCert is false, any other option in Security will be ignored
 	AutoIssueCert bool `mapstructure:"autoIssueCert" yaml:"autoIssueCert"`
 	// CACert is the root CA certificate for all grpc tls handshake, it can be path or PEM format string
-	CACert serialize.PEMContent `mapstructure:"caCert" yaml:"caCert"`
+	CACert types.PEMContent `mapstructure:"caCert" yaml:"caCert"`
 	// TLSPrefer indicates to verify client certificates for grpc ServerHandshake
 	TLSVerify bool `mapstructure:"tlsVerify" yaml:"tlsVerify"`
 	// TLSPolicy controls the grpc shandshake behaviors:
@@ -536,12 +536,12 @@ type UnixListenOption struct {
 
 type SecurityOption struct {
 	// Insecure indicate enable tls or not
-	Insecure  bool                 `mapstructure:"insecure" yaml:"insecure"`
-	CACert    serialize.PEMContent `mapstructure:"caCert" yaml:"caCert"`
-	Cert      serialize.PEMContent `mapstructure:"cert" yaml:"cert"`
-	Key       serialize.PEMContent `mapstructure:"key" yaml:"key"`
-	TLSVerify bool                 `mapstructure:"tlsVerify" yaml:"tlsVerify"`
-	TLSConfig *tls.Config          `mapstructure:"tlsConfig" yaml:"tlsConfig"`
+	Insecure  bool             `mapstructure:"insecure" yaml:"insecure"`
+	CACert    types.PEMContent `mapstructure:"caCert" yaml:"caCert"`
+	Cert      types.PEMContent `mapstructure:"cert" yaml:"cert"`
+	Key       types.PEMContent `mapstructure:"key" yaml:"key"`
+	TLSVerify bool             `mapstructure:"tlsVerify" yaml:"tlsVerify"`
+	TLSConfig *tls.Config      `mapstructure:"tlsConfig" yaml:"tlsConfig"`
 }
 
 type StorageOption struct {
@@ -572,9 +572,9 @@ type ReloadOption struct {
 }
 
 type tlsConfigFiles struct {
-	Cert   serialize.PEMContent `yaml:"cert" json:"cert"`
-	Key    serialize.PEMContent `yaml:"key" json:"key"`
-	CACert serialize.PEMContent `yaml:"caCert" json:"caCert"`
+	Cert   types.PEMContent `yaml:"cert" json:"cert"`
+	Key    types.PEMContent `yaml:"key" json:"key"`
+	CACert types.PEMContent `yaml:"caCert" json:"caCert"`
 }
 
 type TLSConfig struct {
diff --git a/client/config/peerhost_darwin.go b/client/config/peerhost_darwin.go
index 6ce3f919..f22435b4 100644
--- a/client/config/peerhost_darwin.go
+++ b/client/config/peerhost_darwin.go
@@ -30,7 +30,7 @@ import (
 	"d7y.io/dragonfly/v2/pkg/net/fqdn"
 	"d7y.io/dragonfly/v2/pkg/net/ip"
 	"d7y.io/dragonfly/v2/pkg/rpc"
-	"d7y.io/dragonfly/v2/pkg/serialize"
+	"d7y.io/dragonfly/v2/pkg/types"
 )
 
 var peerHostConfig = func() *DaemonOption {
@@ -180,7 +180,7 @@ var peerHostConfig = func() *DaemonOption {
 		},
 		Security: GlobalSecurityOption{
 			AutoIssueCert: false,
-			CACert:        serialize.PEMContent(""),
+			CACert:        types.PEMContent(""),
 			TLSVerify:     false,
 			TLSPolicy:     rpc.DefaultTLSPolicy,
 		},
diff --git a/client/config/peerhost_linux.go b/client/config/peerhost_linux.go
index 12d6427d..538ea4f2 100644
--- a/client/config/peerhost_linux.go
+++ b/client/config/peerhost_linux.go
@@ -30,7 +30,7 @@ import (
 	"d7y.io/dragonfly/v2/pkg/net/fqdn"
 	"d7y.io/dragonfly/v2/pkg/net/ip"
 	"d7y.io/dragonfly/v2/pkg/rpc"
-	"d7y.io/dragonfly/v2/pkg/serialize"
+	"d7y.io/dragonfly/v2/pkg/types"
 )
 
 var peerHostConfig = func() *DaemonOption {
@@ -179,7 +179,7 @@ var peerHostConfig = func() *DaemonOption {
 		},
 		Security: GlobalSecurityOption{
 			AutoIssueCert: false,
-			CACert:        serialize.PEMContent(""),
+			CACert:        types.PEMContent(""),
 			TLSVerify:     false,
 			TLSPolicy:     rpc.DefaultTLSPolicy,
 		},
diff --git a/client/daemon/daemon.go b/client/daemon/daemon.go
index 327ff627..ca56ca78 100644
--- a/client/daemon/daemon.go
+++ b/client/daemon/daemon.go
@@ -26,6 +26,7 @@ import (
 	"net/http"
 	"os"
 	"path"
+	"path/filepath"
 	"runtime"
 	"sync"
 	"time"
@@ -55,6 +56,7 @@ import (
 	"d7y.io/dragonfly/v2/client/util"
 	"d7y.io/dragonfly/v2/cmd/dependency"
 	logger "d7y.io/dragonfly/v2/internal/dflog"
+	internaldynconfig "d7y.io/dragonfly/v2/internal/dynconfig"
 	"d7y.io/dragonfly/v2/pkg/cache"
 	"d7y.io/dragonfly/v2/pkg/dfnet"
 	"d7y.io/dragonfly/v2/pkg/dfpath"
@@ -65,6 +67,7 @@ import (
 	managerclient "d7y.io/dragonfly/v2/pkg/rpc/manager/client"
 	schedulerclient "d7y.io/dragonfly/v2/pkg/rpc/scheduler/client"
 	"d7y.io/dragonfly/v2/pkg/source"
+	"d7y.io/dragonfly/v2/pkg/types"
 )
 
 type Daemon interface {
@@ -156,7 +159,7 @@ func New(opt *config.DaemonOption, d dfpath.Dfpath) (Daemon, error) {
 				Logger:       zapadapter.New(logger.CoreLogger.Desugar()),
 				Cache: cache.NewCertifyMutliCache(
 					certify.NewMemCache(),
-					certify.DirCache(path.Join(d.CacheDir(), cache.DfdaemonCertifyCacheDirName))),
+					certify.DirCache(path.Join(d.CacheDir(), cache.CertifyCacheDirName, types.DfdaemonName))),
 			}
 
 			// issue a certificate to reduce first time delay
@@ -175,7 +178,7 @@ func New(opt *config.DaemonOption, d dfpath.Dfpath) (Daemon, error) {
 		dynconfig, err = config.NewDynconfig(
 			config.ManagerSourceType, opt,
 			config.WithManagerClient(managerClient),
-			config.WithCacheDir(d.CacheDir()),
+			config.WithCacheDir(filepath.Join(d.CacheDir(), internaldynconfig.CacheDirName)),
 			config.WithExpireTime(opt.Scheduler.Manager.RefreshInterval),
 		)
 		if err != nil {
diff --git a/client/daemon/metrics/metrics.go b/client/daemon/metrics/metrics.go
index a9d399a5..5cee8efd 100644
--- a/client/daemon/metrics/metrics.go
+++ b/client/daemon/metrics/metrics.go
@@ -23,7 +23,7 @@ import (
 	"github.com/prometheus/client_golang/prometheus/promauto"
 	"github.com/prometheus/client_golang/prometheus/promhttp"
 
-	"d7y.io/dragonfly/v2/internal/constants"
+	"d7y.io/dragonfly/v2/pkg/types"
 )
 
 const (
@@ -45,120 +45,120 @@ const (
 
 var (
 	ProxyRequestCount = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "proxy_request_total",
 		Help:      "Counter of the total proxy request.",
 	}, []string{"method"})
 
 	ProxyRequestViaDragonflyCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "proxy_request_via_dragonfly_total",
 		Help:      "Counter of the total proxy request via Dragonfly.",
 	})
 
 	ProxyRequestNotViaDragonflyCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "proxy_request_not_via_dragonfly_total",
 		Help:      "Counter of the total proxy request not via Dragonfly.",
 	})
 
 	ProxyRequestRunningCount = promauto.NewGaugeVec(prometheus.GaugeOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "proxy_request_running_total",
 		Help:      "Current running count of proxy request.",
 	}, []string{"method"})
 
 	ProxyRequestBytesCount = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "proxy_request_bytes_total",
 		Help:      "Counter of the total byte of all proxy request.",
 	}, []string{"method"})
 
 	PeerTaskCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "peer_task_total",
 		Help:      "Counter of the total peer tasks.",
 	})
 
 	PeerTaskFailedCount = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "peer_task_failed_total",
 		Help:      "Counter of the total failed peer tasks.",
 	}, []string{"type"})
 
 	PieceTaskCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "piece_task_total",
 		Help:      "Counter of the total failed piece tasks.",
 	})
 
 	PieceTaskFailedCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "piece_task_failed_total",
 		Help:      "Counter of the total failed piece tasks.",
 	})
 
 	FileTaskCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "file_task_total",
 		Help:      "Counter of the total file tasks.",
 	})
 
 	StreamTaskCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "stream_task_total",
 		Help:      "Counter of the total stream tasks.",
 	})
 
 	SeedPeerDownloadCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "seed_peer_download_total",
 		Help:      "Counter of the number of the seed peer downloading.",
 	})
 
 	SeedPeerDownloadFailureCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "seed_peer_download_failure_total",
 		Help:      "Counter of the number of failed of the seed peer downloading.",
 	})
 
 	SeedPeerDownloadTraffic = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "seed_peer_download_traffic",
 		Help:      "Counter of the number of seed peer download traffic.",
 	}, []string{"type"})
 
 	SeedPeerConcurrentDownloadGauge = promauto.NewGauge(prometheus.GaugeOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "seed_peer_concurrent_download_total",
 		Help:      "Gauger of the number of concurrent of the seed peer downloading.",
 	})
 
 	PeerTaskCacheHitCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "peer_task_cache_hit_total",
 		Help:      "Counter of the total cache hit peer tasks.",
 	})
 
 	PrefetchTaskCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.DfdaemonMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.DfdaemonMetricsName,
 		Name:      "prefetch_task_total",
 		Help:      "Counter of the total prefetched tasks.",
 	})
diff --git a/cmd/dependency/dependency.go b/cmd/dependency/dependency.go
index a1538cc3..974da1a2 100644
--- a/cmd/dependency/dependency.go
+++ b/cmd/dependency/dependency.go
@@ -50,7 +50,7 @@ import (
 	"d7y.io/dragonfly/v2/pkg/dfpath"
 	"d7y.io/dragonfly/v2/pkg/net/fqdn"
 	"d7y.io/dragonfly/v2/pkg/net/ip"
-	"d7y.io/dragonfly/v2/pkg/serialize"
+	"d7y.io/dragonfly/v2/pkg/types"
 	"d7y.io/dragonfly/v2/pkg/unit"
 	"d7y.io/dragonfly/v2/version"
 )
@@ -239,7 +239,7 @@ func initDecoderConfig(dc *mapstructure.DecoderConfig) {
 			reflect.TypeOf(util.Duration{}),
 			reflect.TypeOf(&config.ProxyOption{}),
 			reflect.TypeOf(config.TCPListenPortRange{}),
-			reflect.TypeOf(serialize.PEMContent("")),
+			reflect.TypeOf(types.PEMContent("")),
 			reflect.TypeOf(config.URL{}),
 			reflect.TypeOf(config.CertPool{}),
 			reflect.TypeOf(config.Regexp{}):
diff --git a/cmd/dfget/cmd/daemon.go b/cmd/dfget/cmd/daemon.go
index f91d4129..2bb61ec2 100644
--- a/cmd/dfget/cmd/daemon.go
+++ b/cmd/dfget/cmd/daemon.go
@@ -36,6 +36,7 @@ import (
 	"d7y.io/dragonfly/v2/pkg/dfnet"
 	"d7y.io/dragonfly/v2/pkg/dfpath"
 	"d7y.io/dragonfly/v2/pkg/rpc/dfdaemon/client"
+	"d7y.io/dragonfly/v2/pkg/types"
 	"d7y.io/dragonfly/v2/version"
 )
 
@@ -75,7 +76,7 @@ it supports container engine, wget and other downloading tools through proxy fun
 		if err := logger.InitDaemon(cfg.Verbose, cfg.Console, d.LogDir()); err != nil {
 			return fmt.Errorf("init client daemon logger: %w", err)
 		}
-		logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), "daemon"))
+		logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), types.DaemonName))
 
 		return runDaemon(d)
 	},
@@ -112,11 +113,9 @@ func initDaemonDfpath(cfg *config.DaemonOption) (dfpath.Dfpath, error) {
 		options = append(options, dfpath.WithDownloadUnixSocketPath(cfg.Download.DownloadGRPC.UnixListen.Socket))
 	}
 
-	cacheDir := dfpath.DefaultCacheDir
 	if cfg.CacheDir != "" {
-		cacheDir = cfg.CacheDir
+		options = append(options, dfpath.WithCacheDir(cfg.CacheDir))
 	}
-	options = append(options, dfpath.WithCacheDir(cacheDir))
 
 	dataDir := dfpath.DefaultDataDir
 	if cfg.DataDir != "" {
diff --git a/cmd/dfget/cmd/root.go b/cmd/dfget/cmd/root.go
index 5298fb36..e566d244 100644
--- a/cmd/dfget/cmd/root.go
+++ b/cmd/dfget/cmd/root.go
@@ -34,7 +34,6 @@ import (
 	"d7y.io/dragonfly/v2/client/config"
 	"d7y.io/dragonfly/v2/client/dfget"
 	"d7y.io/dragonfly/v2/cmd/dependency"
-	"d7y.io/dragonfly/v2/internal/constants"
 	logger "d7y.io/dragonfly/v2/internal/dflog"
 	"d7y.io/dragonfly/v2/pkg/basic"
 	"d7y.io/dragonfly/v2/pkg/dfnet"
@@ -42,6 +41,7 @@ import (
 	"d7y.io/dragonfly/v2/pkg/net/ip"
 	"d7y.io/dragonfly/v2/pkg/rpc/dfdaemon/client"
 	"d7y.io/dragonfly/v2/pkg/source"
+	"d7y.io/dragonfly/v2/pkg/types"
 	"d7y.io/dragonfly/v2/pkg/unit"
 	"d7y.io/dragonfly/v2/version"
 )
@@ -230,7 +230,7 @@ func runDfget(dfgetLockPath, daemonSockPath string) error {
 		err            error
 	)
 
-	if dfgetConfig.Pattern != constants.SourcePattern {
+	if dfgetConfig.Pattern != types.SourcePattern {
 		logger.Info("start to check and spawn daemon")
 		if dfdaemonClient, err = checkAndSpawnDaemon(dfgetLockPath, daemonSockPath); err != nil {
 			logger.Errorf("check and spawn daemon error: %v", err)
diff --git a/cmd/manager/cmd/root.go b/cmd/manager/cmd/root.go
index a2a2cdef..d4dc3df9 100644
--- a/cmd/manager/cmd/root.go
+++ b/cmd/manager/cmd/root.go
@@ -29,6 +29,7 @@ import (
 	"d7y.io/dragonfly/v2/manager"
 	"d7y.io/dragonfly/v2/manager/config"
 	"d7y.io/dragonfly/v2/pkg/dfpath"
+	"d7y.io/dragonfly/v2/pkg/types"
 	"d7y.io/dragonfly/v2/version"
 )
 
@@ -61,7 +62,7 @@ for managing schedulers and seed peers, offering http apis and portal, etc.`,
 		if err := logger.InitManager(cfg.Verbose, cfg.Console, d.LogDir()); err != nil {
 			return fmt.Errorf("init manager logger: %w", err)
 		}
-		logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), "manager"))
+		logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), types.ManagerName))
 
 		return runManager(d)
 	},
@@ -90,6 +91,10 @@ func initDfpath(cfg *config.ServerConfig) (dfpath.Dfpath, error) {
 		options = append(options, dfpath.WithLogDir(cfg.LogDir))
 	}
 
+	if cfg.CacheDir != "" {
+		options = append(options, dfpath.WithCacheDir(cfg.CacheDir))
+	}
+
 	return dfpath.New(options...)
 }
 
diff --git a/cmd/scheduler/cmd/root.go b/cmd/scheduler/cmd/root.go
index c3550ea9..9eb74a12 100644
--- a/cmd/scheduler/cmd/root.go
+++ b/cmd/scheduler/cmd/root.go
@@ -28,6 +28,7 @@ import (
 	"d7y.io/dragonfly/v2/cmd/dependency"
 	logger "d7y.io/dragonfly/v2/internal/dflog"
 	"d7y.io/dragonfly/v2/pkg/dfpath"
+	"d7y.io/dragonfly/v2/pkg/types"
 	"d7y.io/dragonfly/v2/scheduler"
 	"d7y.io/dragonfly/v2/scheduler/config"
 	"d7y.io/dragonfly/v2/version"
@@ -65,7 +66,7 @@ generate and maintain a P2P network during the download process, and push suitab
 		if err := logger.InitScheduler(cfg.Verbose, cfg.Console, d.LogDir()); err != nil {
 			return fmt.Errorf("init scheduler logger: %w", err)
 		}
-		logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), "scheduler"))
+		logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), types.SchedulerName))
 
 		return runScheduler(ctx, d)
 	},
@@ -97,11 +98,9 @@ func initDfpath(cfg *config.ServerConfig) (dfpath.Dfpath, error) {
 		options = append(options, dfpath.WithLogDir(cfg.LogDir))
 	}
 
-	cacheDir := dfpath.DefaultCacheDir
 	if cfg.CacheDir != "" {
-		cacheDir = cfg.CacheDir
+		options = append(options, dfpath.WithCacheDir(cfg.CacheDir))
 	}
-	options = append(options, dfpath.WithCacheDir(cacheDir))
 
 	dataDir := dfpath.DefaultDataDir
 	if cfg.DataDir != "" {
diff --git a/internal/constants/constants.go b/internal/constants/constants.go
deleted file mode 100644
index bd68d207..00000000
--- a/internal/constants/constants.go
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- *     Copyright 2020 The Dragonfly Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package constants
-
-const (
-	// download pattern
-	SourcePattern   = "source"
-	SeedPeerPattern = "seed-peer"
-	P2PPattern      = "p2p"
-)
-
-const (
-	MetricsNamespace     = "dragonfly"
-	ManagerMetricsName   = "manager"
-	SchedulerMetricsName = "scheduler"
-	DfdaemonMetricsName  = "dfdaemon"
-)
diff --git a/internal/dflog/loginit.go b/internal/dflog/loginit.go
index 7cdfa00c..38ea9974 100644
--- a/internal/dflog/loginit.go
+++ b/internal/dflog/loginit.go
@@ -21,6 +21,8 @@ import (
 	"path/filepath"
 
 	"go.uber.org/zap"
+
+	"d7y.io/dragonfly/v2/pkg/types"
 )
 
 type logInitMeta struct {
@@ -34,7 +36,7 @@ func InitManager(verbose, console bool, dir string) error {
 		return createConsoleLogger(verbose)
 	}
 
-	logDir := filepath.Join(dir, "manager")
+	logDir := filepath.Join(dir, types.ManagerName)
 
 	var meta = []logInitMeta{
 		{
@@ -63,7 +65,7 @@ func InitScheduler(verbose, console bool, dir string) error {
 		return createConsoleLogger(verbose)
 	}
 
-	logDir := filepath.Join(dir, "scheduler")
+	logDir := filepath.Join(dir, types.SchedulerName)
 
 	var meta = []logInitMeta{
 		{
@@ -92,7 +94,7 @@ func InitDaemon(verbose, console bool, dir string) error {
 		return createConsoleLogger(verbose)
 	}
 
-	logDir := filepath.Join(dir, "daemon")
+	logDir := filepath.Join(dir, types.DaemonName)
 
 	var meta = []logInitMeta{
 		{
@@ -117,7 +119,7 @@ func InitDfget(verbose, console bool, dir string) error {
 		return createConsoleLogger(verbose)
 	}
 
-	logDir := filepath.Join(dir, "dfget")
+	logDir := filepath.Join(dir, types.DfgetName)
 
 	var meta = []logInitMeta{
 		{
@@ -178,7 +180,7 @@ func createFileLogger(verbose bool, meta []logInitMeta, logDir string) error {
 }
 
 func InitDfcache(console bool, dir string) error {
-	logDir := filepath.Join(dir, "dfcache")
+	logDir := filepath.Join(dir, types.DfcacheName)
 
 	var meta = []logInitMeta{
 		{
diff --git a/internal/dynconfig/dynconfig.go b/internal/dynconfig/dynconfig.go
index b548aa42..4ff95f57 100644
--- a/internal/dynconfig/dynconfig.go
+++ b/internal/dynconfig/dynconfig.go
@@ -30,6 +30,11 @@ import (
 
 type SourceType string
 
+const (
+	// CacheDirName is dir name of dynconfig cache.
+	CacheDirName = "dynconfig"
+)
+
 const (
 	// defaultCacheKey represents cache key of dynconfig.
 	defaultCacheKey = "dynconfig"
diff --git a/manager/config/config.go b/manager/config/config.go
index 6d03c3f5..4977fd75 100644
--- a/manager/config/config.go
+++ b/manager/config/config.go
@@ -26,8 +26,8 @@ import (
 	"d7y.io/dragonfly/v2/cmd/dependency/base"
 	"d7y.io/dragonfly/v2/pkg/objectstorage"
 	"d7y.io/dragonfly/v2/pkg/rpc"
-	"d7y.io/dragonfly/v2/pkg/serialize"
 	"d7y.io/dragonfly/v2/pkg/slices"
+	"d7y.io/dragonfly/v2/pkg/types"
 )
 
 type Config struct {
@@ -57,6 +57,9 @@ type ServerConfig struct {
 	// Server name.
 	Name string `yaml:"name" mapstructure:"name"`
 
+	// Server dynamic config cache directory.
+	CacheDir string `yaml:"cacheDir" mapstructure:"cacheDir"`
+
 	// Server log directory.
 	LogDir string `yaml:"logDir" mapstructure:"logDir"`
 
@@ -253,10 +256,10 @@ type SecurityConfig struct {
 	AutoIssueCert bool `yaml:"autoIssueCert" mapstructure:"autoIssueCert"`
 
 	// CACert is file path PEM-encoded certificate
-	CACert serialize.PEMContent `mapstructure:"caCert" yaml:"caCert"`
+	CACert types.PEMContent `mapstructure:"caCert" yaml:"caCert"`
 
 	// CAKey is file path of PEM-encoded private key.
-	CAKey serialize.PEMContent `mapstructure:"caKey" yaml:"caKey"`
+	CAKey types.PEMContent `mapstructure:"caKey" yaml:"caKey"`
 
 	// TLSPolicy controls the grpc shandshake behaviors:
 	// force: both ClientHandshake and ServerHandshake are only support tls
diff --git a/manager/manager.go b/manager/manager.go
index a886cfcc..f2b3c4f1 100644
--- a/manager/manager.go
+++ b/manager/manager.go
@@ -47,6 +47,7 @@ import (
 	"d7y.io/dragonfly/v2/pkg/net/ip"
 	"d7y.io/dragonfly/v2/pkg/objectstorage"
 	"d7y.io/dragonfly/v2/pkg/rpc"
+	"d7y.io/dragonfly/v2/pkg/types"
 )
 
 const (
@@ -179,7 +180,7 @@ func New(cfg *config.Config, d dfpath.Dfpath) (*Server, error) {
 			Logger:       zapadapter.New(logger.CoreLogger.Desugar()),
 			Cache: pkgcache.NewCertifyMutliCache(
 				certify.NewMemCache(),
-				certify.DirCache(path.Join(d.CacheDir(), pkgcache.ManagerCertifyCacheDirName))),
+				certify.DirCache(path.Join(d.CacheDir(), pkgcache.CertifyCacheDirName, types.ManagerName))),
 		})
 		if err != nil {
 			return nil, err
diff --git a/manager/metrics/metrics.go b/manager/metrics/metrics.go
index 236cfd1d..74e1acf7 100644
--- a/manager/metrics/metrics.go
+++ b/manager/metrics/metrics.go
@@ -25,8 +25,8 @@ import (
 	"github.com/prometheus/client_golang/prometheus/promhttp"
 	"google.golang.org/grpc"
 
-	"d7y.io/dragonfly/v2/internal/constants"
 	"d7y.io/dragonfly/v2/manager/config"
+	"d7y.io/dragonfly/v2/pkg/types"
 )
 
 func New(cfg *config.MetricsConfig, grpcServer *grpc.Server) *http.Server {
@@ -43,8 +43,8 @@ func New(cfg *config.MetricsConfig, grpcServer *grpc.Server) *http.Server {
 
 var (
 	PeerGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.ManagerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.ManagerMetricsName,
 		Name:      "peer_total",
 		Help:      "Gauge of the number of peer.",
 	}, []string{"version", "commit"})
diff --git a/manager/router/router.go b/manager/router/router.go
index ca5011fc..23494ac1 100644
--- a/manager/router/router.go
+++ b/manager/router/router.go
@@ -35,6 +35,7 @@ import (
 	"d7y.io/dragonfly/v2/manager/handlers"
 	"d7y.io/dragonfly/v2/manager/middlewares"
 	"d7y.io/dragonfly/v2/manager/service"
+	"d7y.io/dragonfly/v2/pkg/types"
 )
 
 const (
@@ -53,7 +54,7 @@ func Init(cfg *config.Config, logDir string, service service.Service, enforcer *
 	// Logging to a file.
 	if !cfg.Console {
 		gin.DisableConsoleColor()
-		logDir := filepath.Join(logDir, "manager")
+		logDir := filepath.Join(logDir, types.ManagerName)
 		f, _ := os.Create(filepath.Join(logDir, GinLogFileName))
 		gin.DefaultWriter = io.MultiWriter(f)
 	}
diff --git a/pkg/cache/certify.go b/pkg/cache/certify.go
index e8a0e385..fcb2559b 100644
--- a/pkg/cache/certify.go
+++ b/pkg/cache/certify.go
@@ -24,14 +24,8 @@ import (
 )
 
 const (
-	// SchedulerCertifyCacheDirName is dir name of scheduler certify cache.
-	SchedulerCertifyCacheDirName = "scheduler-certs"
-
-	// ManagerCertifyCacheDirName is dir name of manager certify cache.
-	ManagerCertifyCacheDirName = "manager-certs"
-
-	// DfdaemonCertifyCacheDirName is dir name of dfdaemon certify cache.
-	DfdaemonCertifyCacheDirName = "dfdaemon-certs"
+	// CertifyCacheDirName is dir name of certify cache.
+	CertifyCacheDirName = "certs"
 )
 
 type certifyCache struct {
diff --git a/pkg/dfpath/dfpath.go b/pkg/dfpath/dfpath.go
index 10596817..6cafd379 100644
--- a/pkg/dfpath/dfpath.go
+++ b/pkg/dfpath/dfpath.go
@@ -111,6 +111,7 @@ func New(options ...Option) (Dfpath, error) {
 			workHome:       DefaultWorkHome,
 			logDir:         DefaultLogDir,
 			pluginDir:      DefaultPluginDir,
+			cacheDir:       DefaultCacheDir,
 			daemonSockPath: DefaultDownloadUnixSocketPath,
 		}
 
@@ -143,10 +144,8 @@ func New(options ...Option) (Dfpath, error) {
 		}
 
 		// Create cache directory.
-		if d.cacheDir != "" {
-			if err := os.MkdirAll(d.cacheDir, fs.FileMode(0755)); err != nil {
-				cache.err = multierror.Append(cache.err, err)
-			}
+		if err := os.MkdirAll(d.cacheDir, fs.FileMode(0755)); err != nil {
+			cache.err = multierror.Append(cache.err, err)
 		}
 
 		// Create data directory.
diff --git a/pkg/types/constants.go b/pkg/types/constants.go
new file mode 100644
index 00000000..56f1f69a
--- /dev/null
+++ b/pkg/types/constants.go
@@ -0,0 +1,65 @@
+/*
+ *     Copyright 2022 The Dragonfly Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package types
+
+const (
+	// ManagerName is name of manager.
+	ManagerName = "manager"
+
+	// SchedulerName is name of scheduler.
+	SchedulerName = "scheduler"
+
+	// DfdaemonName is name of dfdaemon.
+	DfdaemonName = "dfdaemon"
+
+	// DaemonName is daemon name of dfdaemon.
+	DaemonName = "daemon"
+
+	// DfgetName is dfget name of dfdaemon.
+	DfgetName = "dfget"
+
+	// DfcacheName is dfcache name of dfdaemon.
+	DfcacheName = "dfcache"
+
+	// DfstoreName is dfstore name of dfdaemon.
+	DfstoreName = "dfstore"
+)
+
+const (
+	// SourcePattern is back-to-source download pattern.
+	SourcePattern = "source"
+
+	// SeedPeerPattern is seed peer download pattern.
+	SeedPeerPattern = "seed-peer"
+
+	// P2PPattern is p2p download pattern.
+	P2PPattern = "p2p"
+)
+
+const (
+	// MetricsNamespace is namespace of metrics.
+	MetricsNamespace = "dragonfly"
+
+	// ManagerMetricsName is name of manager metrics.
+	ManagerMetricsName = "manager"
+
+	// SchedulerMetricsName is name of scheduelr metrics.
+	SchedulerMetricsName = "scheduler"
+
+	// DfdaemonMetricsName is name of dfdaemon metrics.
+	DfdaemonMetricsName = "dfdaemon"
+)
diff --git a/pkg/serialize/pemcontent.go b/pkg/types/types.go
similarity index 98%
rename from pkg/serialize/pemcontent.go
rename to pkg/types/types.go
index 5a728b40..72bf626d 100644
--- a/pkg/serialize/pemcontent.go
+++ b/pkg/types/types.go
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package serialize
+package types
 
 import (
 	"encoding/json"
diff --git a/scheduler/config/config.go b/scheduler/config/config.go
index d6cb3360..9f1fc5b8 100644
--- a/scheduler/config/config.go
+++ b/scheduler/config/config.go
@@ -24,7 +24,7 @@ import (
 	"d7y.io/dragonfly/v2/pkg/net/fqdn"
 	"d7y.io/dragonfly/v2/pkg/net/ip"
 	"d7y.io/dragonfly/v2/pkg/rpc"
-	"d7y.io/dragonfly/v2/pkg/serialize"
+	"d7y.io/dragonfly/v2/pkg/types"
 	"d7y.io/dragonfly/v2/scheduler/storage"
 )
 
@@ -459,7 +459,7 @@ type SecurityConfig struct {
 	AutoIssueCert bool `mapstructure:"autoIssueCert" yaml:"autoIssueCert"`
 
 	// CACert is the root CA certificate for all grpc tls handshake, it can be path or PEM format string.
-	CACert serialize.PEMContent `mapstructure:"caCert" yaml:"caCert"`
+	CACert types.PEMContent `mapstructure:"caCert" yaml:"caCert"`
 
 	// TLSPrefer indicates to verify client certificates for grpc ServerHandshake.
 	TLSVerify bool `mapstructure:"tlsVerify" yaml:"tlsVerify"`
diff --git a/scheduler/config/dynconfig.go b/scheduler/config/dynconfig.go
index 8ad125d5..6c292970 100644
--- a/scheduler/config/dynconfig.go
+++ b/scheduler/config/dynconfig.go
@@ -39,7 +39,7 @@ import (
 
 var (
 	// Cache filename.
-	cacheFileName = "scheduler_dynconfig"
+	cacheFileName = "scheduler"
 
 	// Notify observer interval.
 	watchInterval = 10 * time.Second
diff --git a/scheduler/metrics/metrics.go b/scheduler/metrics/metrics.go
index cceb8a87..5baecbe8 100644
--- a/scheduler/metrics/metrics.go
+++ b/scheduler/metrics/metrics.go
@@ -25,7 +25,7 @@ import (
 	"github.com/prometheus/client_golang/prometheus/promhttp"
 	"google.golang.org/grpc"
 
-	"d7y.io/dragonfly/v2/internal/constants"
+	"d7y.io/dragonfly/v2/pkg/types"
 	"d7y.io/dragonfly/v2/scheduler/config"
 )
 
@@ -52,114 +52,114 @@ var (
 // Variables declared for metrics.
 var (
 	RegisterPeerTaskCount = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "register_peer_task_total",
 		Help:      "Counter of the number of the register peer task.",
 	}, []string{"tag", "app"})
 
 	RegisterPeerTaskFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "register_peer_task_failure_total",
 		Help:      "Counter of the number of failed of the register peer task.",
 	}, []string{"tag", "app"})
 
 	DownloadCount = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "download_total",
 		Help:      "Counter of the number of the downloading.",
 	}, []string{"tag", "app"})
 
 	DownloadFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "download_failure_total",
 		Help:      "Counter of the number of failed of the downloading.",
 	}, []string{"tag", "app", "type"})
 
 	StatTaskCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "stat_task_total",
 		Help:      "Counter of the number of the stat task.",
 	})
 
 	StatTaskFailureCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "stat_task_failure_total",
 		Help:      "Counter of the number of failed of the stat task.",
 	})
 
 	AnnounceCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "announce_task_total",
 		Help:      "Counter of the number of the announce task.",
 	})
 
 	AnnounceFailureCount = promauto.NewCounter(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "announce_task_failure_total",
 		Help:      "Counter of the number of failed of the announce task.",
 	})
 
 	LeaveTaskCount = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "leave_task_total",
 		Help:      "Counter of the number of the leaving task.",
 	}, []string{"tag", "app"})
 
 	LeaveTaskFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "leave_task_failure_total",
 		Help:      "Counter of the number of failed of the leaving task.",
 	}, []string{"tag", "app"})
 
 	Traffic = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "traffic",
 		Help:      "Counter of the number of traffic.",
 	}, []string{"tag", "app", "type"})
 
 	PeerHostTraffic = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "peer_host_traffic",
 		Help:      "Counter of the number of per peer host traffic.",
 	}, []string{"tag", "app", "traffic_type", "peer_host_id", "peer_host_ip"})
 
 	PeerTaskCounter = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "peer_task_total",
 		Help:      "Counter of the number of peer task.",
 	}, []string{"tag", "app", "type"})
 
 	PeerTaskSourceErrorCounter = promauto.NewCounterVec(prometheus.CounterOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "peer_task_source_error_total",
 		Help:      "Counter of the source error code number of peer task.",
 	}, []string{"tag", "app", "protocol", "code"})
 
 	PeerTaskDownloadDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "peer_task_download_duration_milliseconds",
 		Help:      "Histogram of the time each peer task downloading.",
 		Buckets:   []float64{100, 200, 500, 1000, 1500, 2 * 1000, 3 * 1000, 5 * 1000, 10 * 1000, 20 * 1000, 60 * 1000, 120 * 1000, 300 * 1000},
 	}, []string{"tag", "app"})
 
 	ConcurrentScheduleGauge = promauto.NewGauge(prometheus.GaugeOpts{
-		Namespace: constants.MetricsNamespace,
-		Subsystem: constants.SchedulerMetricsName,
+		Namespace: types.MetricsNamespace,
+		Subsystem: types.SchedulerMetricsName,
 		Name:      "concurrent_schedule_total",
 		Help:      "Gauge of the number of concurrent of the scheduling.",
 	})
diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go
index 04bfd12f..f9ab4145 100644
--- a/scheduler/scheduler.go
+++ b/scheduler/scheduler.go
@@ -21,7 +21,7 @@ import (
 	"fmt"
 	"net"
 	"net/http"
-	"path"
+	"path/filepath"
 	"time"
 
 	"github.com/johanbrandhorst/certify"
@@ -32,6 +32,7 @@ import (
 	managerv1 "d7y.io/api/pkg/apis/manager/v1"
 
 	logger "d7y.io/dragonfly/v2/internal/dflog"
+	"d7y.io/dragonfly/v2/internal/dynconfig"
 	"d7y.io/dragonfly/v2/pkg/cache"
 	"d7y.io/dragonfly/v2/pkg/dfpath"
 	"d7y.io/dragonfly/v2/pkg/gc"
@@ -39,6 +40,7 @@ import (
 	"d7y.io/dragonfly/v2/pkg/net/ip"
 	"d7y.io/dragonfly/v2/pkg/rpc"
 	managerclient "d7y.io/dragonfly/v2/pkg/rpc/manager/client"
+	"d7y.io/dragonfly/v2/pkg/types"
 	"d7y.io/dragonfly/v2/scheduler/config"
 	"d7y.io/dragonfly/v2/scheduler/job"
 	"d7y.io/dragonfly/v2/scheduler/metrics"
@@ -117,7 +119,7 @@ func New(ctx context.Context, cfg *config.Config, d dfpath.Dfpath) (*Server, err
 	}
 
 	// Initialize dynconfig client.
-	dynconfig, err := config.NewDynconfig(s.managerClient, d.CacheDir(), cfg)
+	dynconfig, err := config.NewDynconfig(s.managerClient, filepath.Join(d.CacheDir(), dynconfig.CacheDirName), cfg)
 	if err != nil {
 		return nil, err
 	}
@@ -138,7 +140,7 @@ func New(ctx context.Context, cfg *config.Config, d dfpath.Dfpath) (*Server, err
 			Logger:       zapadapter.New(logger.CoreLogger.Desugar()),
 			Cache: cache.NewCertifyMutliCache(
 				certify.NewMemCache(),
-				certify.DirCache(path.Join(d.CacheDir(), cache.SchedulerCertifyCacheDirName))),
+				certify.DirCache(filepath.Join(d.CacheDir(), cache.CertifyCacheDirName, types.SchedulerName))),
 		}
 	}
 
diff --git a/version/version.go b/version/version.go
index 47be4ea2..7215169a 100644
--- a/version/version.go
+++ b/version/version.go
@@ -22,7 +22,7 @@ import (
 	"github.com/prometheus/client_golang/prometheus"
 	"github.com/prometheus/client_golang/prometheus/promauto"
 
-	"d7y.io/dragonfly/v2/internal/constants"
+	"d7y.io/dragonfly/v2/pkg/types"
 )
 
 var (
@@ -39,7 +39,7 @@ var (
 
 var (
 	versionGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
-		Namespace: constants.MetricsNamespace,
+		Namespace: types.MetricsNamespace,
 		Name:      "version",
 		Help:      "Version info of dragonfly components.",
 	}, []string{"major", "minor", "git_version", "git_commit", "platform", "build_time", "go_version", "go_tags", "go_gcflags"})


Test patch:
diff --git a/client/config/peerhost_test.go b/client/config/peerhost_test.go
index 7c657e1b..d68e9972 100644
--- a/client/config/peerhost_test.go
+++ b/client/config/peerhost_test.go
@@ -31,7 +31,7 @@ import (
 	"d7y.io/dragonfly/v2/cmd/dependency/base"
 	"d7y.io/dragonfly/v2/manager/model"
 	"d7y.io/dragonfly/v2/pkg/dfnet"
-	"d7y.io/dragonfly/v2/pkg/serialize"
+	"d7y.io/dragonfly/v2/pkg/types"
 	"d7y.io/dragonfly/v2/pkg/unit"
 )
 
@@ -226,9 +226,9 @@ func TestPeerHostOption_Load(t *testing.T) {
 	_cert, _ := os.ReadFile("./testdata/certs/sca.crt")
 	_key, _ := os.ReadFile("./testdata/certs/sca.key")
 
-	caCert := serialize.PEMContent(strings.TrimSpace(string(_caCert)))
-	cert := serialize.PEMContent(strings.TrimSpace(string(_cert)))
-	key := serialize.PEMContent(strings.TrimSpace(string(_key)))
+	caCert := types.PEMContent(strings.TrimSpace(string(_caCert)))
+	cert := types.PEMContent(strings.TrimSpace(string(_cert)))
+	key := types.PEMContent(strings.TrimSpace(string(_key)))
 
 	peerHostOption := &DaemonOption{
 		Options: base.Options{
diff --git a/manager/config/config_test.go b/manager/config/config_test.go
index 75143707..b25d7d9e 100644
--- a/manager/config/config_test.go
+++ b/manager/config/config_test.go
@@ -32,8 +32,9 @@ func TestManagerConfig_Load(t *testing.T) {
 
 	config := &Config{
 		Server: &ServerConfig{
-			Name:   "foo",
-			LogDir: "foo",
+			Name:     "foo",
+			CacheDir: "foo",
+			LogDir:   "foo",
 			GRPC: &TCPListenConfig{
 				Listen: "127.0.0.1",
 				PortRange: TCPListenPortRange{
diff --git a/manager/config/testdata/manager.yaml b/manager/config/testdata/manager.yaml
index 7b25ffe3..ecf50131 100644
--- a/manager/config/testdata/manager.yaml
+++ b/manager/config/testdata/manager.yaml
@@ -1,5 +1,6 @@
 server:
   name: foo
+  cacheDir: foo
   logDir: foo
   grpc:
     listen: 127.0.0.1
diff --git a/pkg/dfpath/dfpath_test.go b/pkg/dfpath/dfpath_test.go
index f0c5ba94..7feaa5f8 100644
--- a/pkg/dfpath/dfpath_test.go
+++ b/pkg/dfpath/dfpath_test.go
@@ -48,7 +48,7 @@ func TestNew(t *testing.T) {
 				d, err := New(options...)
 				assert.NoError(err)
 				assert.Equal(d.WorkHome(), DefaultWorkHome)
-				assert.Equal(d.CacheDir(), "")
+				assert.Equal(d.CacheDir(), DefaultCacheDir)
 				assert.Equal(d.LogDir(), DefaultLogDir)
 				assert.Equal(d.DataDir(), "")
 				assert.Equal(d.PluginDir(), DefaultPluginDir)
@@ -65,7 +65,7 @@ func TestNew(t *testing.T) {
 				d, err := New(options...)
 				assert.NoError(err)
 				assert.Equal(d.WorkHome(), "foo")
-				assert.Equal(d.CacheDir(), "")
+				assert.Equal(d.CacheDir(), DefaultCacheDir)
 				assert.Equal(d.LogDir(), DefaultLogDir)
 				assert.Equal(d.DataDir(), "")
 				assert.Equal(d.PluginDir(), DefaultPluginDir)
@@ -98,7 +98,7 @@ func TestNew(t *testing.T) {
 				d, err := New(options...)
 				assert.NoError(err)
 				assert.Equal(d.WorkHome(), DefaultWorkHome)
-				assert.Equal(d.CacheDir(), "")
+				assert.Equal(d.CacheDir(), DefaultCacheDir)
 				assert.Equal(d.LogDir(), "foo")
 				assert.Equal(d.DataDir(), "")
 				assert.Equal(d.PluginDir(), DefaultPluginDir)
@@ -115,7 +115,7 @@ func TestNew(t *testing.T) {
 				d, err := New(options...)
 				assert.NoError(err)
 				assert.Equal(d.WorkHome(), DefaultWorkHome)
-				assert.Equal(d.CacheDir(), "")
+				assert.Equal(d.CacheDir(), DefaultCacheDir)
 				assert.Equal(d.LogDir(), DefaultLogDir)
 				assert.Equal(d.DataDir(), "")
 				assert.Equal(d.PluginDir(), "foo")
@@ -132,7 +132,7 @@ func TestNew(t *testing.T) {
 				d, err := New(options...)
 				assert.NoError(err)
 				assert.Equal(d.WorkHome(), DefaultWorkHome)
-				assert.Equal(d.CacheDir(), "")
+				assert.Equal(d.CacheDir(), DefaultCacheDir)
 				assert.Equal(d.LogDir(), DefaultLogDir)
 				assert.Equal(d.DataDir(), "")
 				assert.Equal(d.PluginDir(), DefaultPluginDir)