grav icon indicating copy to clipboard operation
grav copied to clipboard

FileStorage Adapter

Open OleVik opened this issue 6 years ago • 2 comments

PSR-16 compliant adapter for abstract handling of transient and persistent files. The difference from FileCache.php is that the implementation is not outright set up for caching with Grav's normal setup, but rather a destination must be explicitly given. Otherwise they largely overlap.

For an example use, see this SchemaBlueprintCommand.php, where plugin option determine the permanence of the file. Ie., transient for normal /cache, native for within-plugin (busted on new version), or persist for /user/data. This command intentionally deletes the file regardless, elsewhere it is used to check for existence or recreate (planned features in the plugin).

@mahagr Thoughts? I dropped the Symfony-components.

OleVik avatar Sep 09 '18 13:09 OleVik

Is there a way to extend the FileCache and just override constructor and getFile() methods? It may need AbstractFileCache base class without the constructor, though :) Think about it.

Also, make sure that cache allows persistent caching without any timeouts.

mahagr avatar Oct 23 '18 16:10 mahagr

There is, largely, but not without switching from private to protected on FileCache's init() and write(). Also, is it preferable to keep the ttl and key in the output when the file is stored - and not cached - like this? Because of doSet(), both will occupy a line each.

Eg., from the reference-command in the initial proposal, the resulting files ends up:

1540633949
Event.schema.json
s:389:"{"Schema":{"Thing":{"Event":{"BusinessEvent":null,"ChildrensEvent":null,"ComedyEvent":null,"DanceEvent":null,"DeliveryEvent":null,"EducationEvent":null,"Festival":null,"FoodEvent":null,"LiteraryEvent":null,"MusicEvent":null,"PublicationEvent":{"BroadcastEvent":null,"OnDemandEvent":null},"SaleEvent":null,"SocialEvent":null,"SportsEvent":null,"TheaterEvent":null,"VisualArtsEvent":null}}}}";

Wouldn't I also have to override write() to preempt the ttl-check when extending FileCache?

OleVik avatar Oct 27 '18 10:10 OleVik