Skip to content

Add auto-dispose to cache streams #7

@Colton127

Description

@Colton127

As of now, only cache streams dynamically created via HttpCacheServer support auto-dispose. I think all cache streams should support this feature, with "auto dispose delay" duration being configurable in cache configuration.

Streams that are automatically disposed of need to retain the ability to be re-created on demand when needed. Perhaps the cache manager could keep a map of "inactive cache streams", which retains the original sourceUrl, cacheFile, and stream cache config of previously disposed cache streams. The cache manager could then automatically re-create cache streams from the given inactive cache stream data.

With the above, the dispose function on cache streams should expose an optional "inactivate" boolean value that, when left null, is determined by the presence of "auto dispose delay" in the cache configuration.

The issue I am facing is how to manage the lifecycle of cache streams given the existing retain/dispose implementation. Cache streams are retained when created, and calling dispose decreases the retain count, with the stream being disposed when the retain count reaches 0. This implementation works fine for the cache server since it handles the creation of streams, but there needs to be a way to auto dispose manually created streams.

Perhaps manually created streams need to be manually disposed of. In this scenario, the cache manager would expose a function to create an "inactive" stream with the same input parameters as createStream. The stream would then automatically be created when a request is made on the returned cacheUrl, and disposed of after all requests are closed after a given duration.

Another scenario is to allow auto disposal of cache streams with a retainCount of 1. This means you could manually create a stream, pre-cache, etc., but auto-dispose would still work as expected. This would also make things a bit easier to handle, as cache streams begin at 1.

In either case, I think retainCount should be preserved for users, and not dependent upon active requests. There needs to be a way to track open request count. Either the close function on StreamResponse should do it, or it should be done manually. Right now, HttpCacheServer has the safest implementation - responding to the HttpRequest.response.done future directly. This top-down approach is ideal, and could be implemented via the RequestHandler directly. There's no guarantee that a StreamResponse is always returned from request.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions