Skip to content

v0.2.1

Choose a tag to compare

@github-actions github-actions released this 26 Nov 23:51
aider: Make the cache size configurable.

# Aider chat conversation:

USER: Make the cache size configurable

ASSISTANT: To make the cache size configurable, we need to modify `main.go` to:

1. Add a new global variable for the cache size.
2. Add a new command-line flag to set the cache size.
3. Use the value from the command-line flag or environment variable to set the cache size when creating the cache.

Here are the *SEARCH/REPLACE* blocks:

main.go
<source>go
<<<<<<< SEARCH
var (
	port            int
	listenAddr      string
	allowedDomains  map[string]bool
	allowAllDomains bool
	clientTimeout   time.Duration
	useTLS          bool
	certDomains     string
	client          *http.Client
	cache           *lru.Cache
	cacheMutex      sync.RWMutex
)
=======
var (
	port            int
	listenAddr      string
	allowedDomains  map[string]bool
	allowAllDomains bool
	clientTimeout   time.Duration
	useTLS          bool
	certDomains     string
	cacheSize       int
	client          *http.Client
	cache           *lru.Cache
	cacheMutex      sync.RWMutex
)
>>>>>>> REPLACE
</source>

main.go
<source>go
<<<<<<< SEARCH
	flag.Parse()
=======
	var cacheSizeEnv int
	flag.IntVar(&cacheSize, "cache-size", getEnvAsInt("CORSAIR_CACHE_SIZE", 100), "Size of the cache")
	cacheSizeEnv = getEnvAsInt("CORSAIR_CACHE_SIZE", cacheSize)
	flag.Parse()
	cacheSize = cacheSizeEnv
>>>>>>> REPLACE
</source>

main.go
<source>go
<<<<<<< SEARCH
	cache, err = lru.New(100) // Cache size of 100
=======
	cache, err = lru.New(cacheSize)
>>>>>>> REPLACE
</source>

README.md
<source>markdown
<<<<<<< SEARCH
- `CORSAIR_USE_HTTPS`: Set to `true` to enable HTTPS support using CertMagic. Defaults to `false` if not set.
- `CORSAIR_CERT_DOMAINS`: Comma-separated list of domains for the TLS certificate. Required if `CORSAIR_USE_HTTPS` is `true`.
=======
- `CORSAIR_USE_HTTPS`: Set to `true` to enable HTTPS support using CertMagic. Defaults to `false` if not set.
- `CORSAIR_CERT_DOMAINS`: Comma-separated list of domains for the TLS certificate. Required if `CORSAIR_USE_HTTPS` is `true`.
- `CORSAIR_CACHE_SIZE`: Size of the cache. Defaults to `100` if not set.
>>>>>>> REPLACE
</source>

Please note that the `getEnvAsInt` function is used to read the environment variable for the cache size and provide a default value if it is not set. The command-line flag `--cache-size` is also added to allow the user to specify the cache size when running the program.