Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor cache configuration #1

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

mcaskill
Copy link
Member

Replace the antiquated settings with a modern structure based on Stash's Symfony bundle.

Objectives

  1. Rename prefix to namespace for clarity.
  2. Deprecate config option types — the fallback driver concept is prone to unexpected behaviors and is unnecessary given with local environment settings.
  3. Deprecate container entries cache/available-drivers, cache/drivers, cache/driver — Unnecessary overhead and broken. On top of it, the way settings must be defined in the config, this was always an unmanageable cross-driver headache.
  4. Provide a PSR-16-compliant variant to the cache pool facade (or vice versa)

Proposed configuration structure

{
	"cache": {
		"active": true,

		"default_namespace": "charcoal",
		"default_ttl": 604800,

		"default_pool_class": "\\Stash\\Pool",
		"default_item_class": "\\Stash\\Item",

		"pools": {
			"first": {
				"drivers": {
					"FileSystem": {
						
					}
				}
			},
			"second": {
				"drivers": [ "Apc", "FileSystem" ],
				"in_memory": false,

				"pool_class": "\\MyApp\\Service\\Cache\\Pool",
				"item_class": "\\MyApp\\Service\\Cache\\Item",

				"namespace": "myapp",
				"default_ttl": 86400,
				"logger": "logger"
			}
		},
		"default_pool": "first",

		"facades": {
			"first": {}
		},
		"default_facade": "first",

		"drivers": {
			
		}
	}
}
// Pools
$first  = $container['cache'];
$first  = $container['cache/default_pool'];
$first  = $container['cache/pools']['first'];
$second = $container['cache/pools']['second'];

// Facades
$first  = $container['cache/facade'];
$first  = $container['cache/default_facade'];
$first  = $container['cache/facades']['first'];

Possible future configuration advantages

{
	"charcoal": {
		"orm": {
			"metadata_cache_driver": "cache/default_pool",
			"query_cache_driver": "cache/default_pool.second",
			"result_cache_driver": "array"
		},
		"dbal": {
			"connections": {
				"default": {
					
				}
			},
			"default_connection": "default"
		}
	}
}

mcaskill and others added 5 commits March 11, 2019 15:59
Changed into a service factory to ensure it always returns the current list, in case another service provider registers new drivers.
Required:
- PHP v5.6+ to v7.3+ or v8.0+
- locomotivemtl/charcoal-config v0.8 → v0.10
- tedvim/stash v0.14 → v0.17

Changed:
- Prefixed getter methods with `get`.
Changed:
- Renamed method `registerService()` to `registerServices()`.
- Visibility from private to protected for method `registerMiddleware()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant