craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 57 forks source link

add tag dependency when setting cache #123

Closed oddnavy closed 3 years ago

oddnavy commented 4 years ago

Replicated from craftcms GraphQL implementation to make it possible to clear the element-api cache without resorting to cache->flush().

We'd like to programmatically clear the element-api cache when entries are saved using TagDependency.

For example:

TagDependency::invalidate(Craft::$app->getCache(), 'elementapi');
oddnavy commented 4 years ago

@brandonkelly / Craft team it would be great if you could take a quick look at this one

oddnavy commented 4 years ago

@angrybrad / anyone? Would love to get this merged if possible

bymayo commented 3 years ago

FYI we did something similar for Orders from Commerce:

Event::on(
            Order::class,
            Order::EVENT_AFTER_COMPLETE_ORDER,
            function(Event $event) {

                BusinessLogic::$instance->api->invalidateCache();

            }
        );
public function invalidateCache()
    {
        TagDependency::invalidate(Craft::$app->getCache(), 'element-api');
    }