Get model changes on save event If an model/element gets changed then I can know about it by listening to an event like onBeforeSaveEntry. This will provide me with the latest version of the model/event, but doesn't give me the changes. Something like this would be great.

craft()-&gt;on('elements.onSaveElement', function (Event $event) {
    $element = $event-&gt;params['element'];

    // $changes = ['uri' =&gt; ['old' =&gt; 'index', 'new' =&gt; 'index2']]
    $changes = $element-&gt;getUnsavedChanges(); 
}


I generate a routes.js that the client uses to generate menu and other stuff. I would like to listen to uri/slug changes so I can clear my (varnish) cache to update internal links. I'd like to prevent clearing my whole site if just one tiny thing gets changed. Any idea's how I can get the model changes or work around this issue?
You have to listen to the onBeforeSaveEntry event, then query the database for the existing entry (if one exists).

craft()-&gt;on('entries.onBeforeSaveEntry', function(Event $e)
{
    if(!$e-&gt;params['isNewEntry'])
    {
        $updatedEntry = $e-&gt;params['entry'];
        $currentEntry = craft()-&gt;entries-&gt;getEntryById($updatedEntry-&gt;id);

        if($updatedEntry-&gt;getUrl() != $currentEntry-&gt;getUrl())
        {
            // Do your thing
        }
    }
});


It might also be worth checking if the updated entry even has a URL, so you could skip that DB query if you don't need it.

You have to be careful with this event though - there's always the possibility the transaction could fail and the updated entry won't get saved to the DB. In that case, you might want to also listen to the onSaveEntry event (if you're doing anything other than writing to the DB - this would get rolled back automatically if something fails) as a way of checking if everything went okay.