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

Create cache directory if it does not exist #18

Open
gruhn opened this issue Jul 18, 2018 · 2 comments
Open

Create cache directory if it does not exist #18

gruhn opened this issue Jul 18, 2018 · 2 comments

Comments

@gruhn
Copy link

gruhn commented Jul 18, 2018

When the configured cache directory does not exist PHP will throw an error. I guess because file_put_contents relies on the file path to exist.

Sure it's not a big deal to create the directory manually. I assume most folks don't want to track the cache files in version control though so they are likely to list the cache directory in .gitignore. Since you can't really track the directory itself while excluding all files within, you have to create the cache directory every time you pull a fresh copy of the project.

Although there are workarounds I think it's slightly more convenient to create the directory when it does not exist. Unless of course there is a specific disadvantage I can't think of right now.

@Blackskyliner
Copy link
Collaborator

Problem here is: If we create the cache in production code (aka the Syllable class) we have a problem if used with Composer, because if you would not change the Cache-Dir outside of the preconfigured __DIR__ you would have cache files created within the vendor directory. (where it strictly does not belong)

This may or may not be a "problem" if you have shared vendors across same-plattform multiple-instances Projects which would use syllable w/o manually configuring the cache dir per instance.

Tests on master already will create a cache, but I would vote not to automatically create directories within the class and thus in productive code itself. We could however throw a RuntimeException to notify the User to create or configure a cache directory.

I guess the real alternative would be not to auto-wire dependencies itself within its own constructor.
This would lead to a decrease in Developer Experience as there would be more to configure initially, but then we could have the Cacheing Component have a auto-create-if-not-exists logic as there would be no DIR default anymore that would point into the vendor dir.

Though the cache adapter used by Syllable could just adhere to PSR-6 (https://www.php-fig.org/psr/psr-6/) whereas we could just use already existing cache providers, even those not living in the Filesystem but inside Cloud or Memory Adapters, which in return will already create the necessary structure if not already existent.

Both last paragraphs would however lead into a big BC because of changes how the initialisation of the whole library would have to work.

@vanderlee vanderlee reopened this Jul 20, 2018
@vanderlee
Copy link
Owner

I like the idea of supporting a standard caching mechanism, but it would have significant impact on existing users. Perhaps if we can find a way to make this work transparently by default.

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

No branches or pull requests

3 participants