Caching with AOP in FLOW3

When it comes to performance optimizing, caching is quite an effective way to boost the speed of your site. In this example we want to cache tweets from Twitter. We do not want to fetch data from Twitter every time the page is called because the data transfer with Twitter is quite time consuming.

1st step: Configure a cache “manifest”

These five lines go into your MyPackage/Configuration/Caches.yaml

In addition to that we also need to wire our tweetsCache to our class property tweetsCache which we will use later in our service class.

2nd step: Dependency Injection

Now we are able to access our cache with $this->tweetsCache. I am using a service class which fetches the tweets.

3rd step: Cache it!

The logic is pretty simple:

  1. Create a cache identifier with
  2. Check if there is a valid cache entry
  3. If the cache entry is invalid (because it has never been called or its lifetime ended) we need to fetch the tweets from Twitter and afterwards write the data to the cache

And this is it! Now we can track how long it takes to fetch the data from Twitter and compare it to reading from the cache. This can be achieved with AOP and I will cover this in a separate blog post.

UPDATE: Please note that every mention of FLOW3 changed to Flow since the release of TYPO3 Flow version 2.