Melissa Stone this should be a global setting IMO ( stated in the last sentence of "the solution"). Everything in the ticket still looks correct in today's world.
off the top of my head, I think the only difference with versioned-deploys would be that we'd presumably want to clean up all versions of an environment. But even then, any leftover dirs should get cleaned up by the versioned-dirs-ttl.
I think the easiest approach would be to define an environment_ttl setting in puppet and a new type of cache entry (https://github.com/puppetlabs/puppet/blob/ec8bcbd5287ccdd67ff06618bb2d0d568a3f2328/lib/puppet/environments.rb#L437-L447) that keeps track of when the environment was last accessed. In order to eagerly evict environments, we could use Concurrent::TimerTask to evict expired environments. We'd also need to remove the environment_timeout setting at the same time.
I think it would be difficult to implement this in puppetserver, because we still need to support the "never cache" vs "cache if unused after" use cases, where "never cache" would still be the default.
Adds a new setting `environment_ttl` which is controls the environment cache like the `environment_timeout` setting. However, `environment_ttl` will evict environments from the cache if they haven't been recently used to compile a catalog within the last `environment_ttl` seconds. This is different from the `environment_timeout` setting which will evict environments at a specific time, regardless of whether the environment has been recently used or not.
For the `environment_ttl` setting, a value of `0` will disable caching. This setting can also be set to`unlimited`, which will cache environments until the server is restarted or told to refresh the cache. All other values will result in Puppet server evicting environments that have not been accessed within that ttl.
You should change this setting once your Puppet deployment is doing non-trivial work. We chose the default value of `0` because it lets new users update their code without any extra steps, but it lowers the performance of your Puppet server.
We recommend setting this to a number that will keep your most actively used environments cached, but allow testing environments to fall out of the cache and reduce memory usage. A value of 3 minutes (3m) is a reasonable value.
Once you set `environment_ttl` to a non-zero value, you need to tell Puppet server to read new code from disk using the `environment-cache` API endpoint after you deploy new code. See the docs for the Puppet Server [administrative API](https://puppet.com/docs/puppetserver/latest/admin-api/v1/environment-cache.html).
If the `environment_ttl` setting is explicitly configured in `puppet.conf` then it will override whatever global `environment_timeout` is set in `puppet.conf` and any per-environment `environment_timeout` set in `$codedir/environments/<environment>/environment.conf`.