Skip to content

Conversation

@onnimonni
Copy link
Contributor

Hello!

I just love to use transients for almost everything in WordPress. It enhances loading speeds significantly. But I'm always frustrated how ugly it looks:

if (false === ( $resources = get_transient( 'my-resources' ) ) ) {
    $resources = Resource::all($start,$end);
    set_transient( 'my-resources', $resources );
}

I used anonymous functions to create Cache class so you could refactor upper code example into:

$resources = Cache::store('my-resources',function() {
    return Resource::all($start,$end);
});

This should be familiar for all javascript guys using herbert.
This also respects Pragma: no-cache headers from the request.

There might be better and more readable ways than this but I'm adding it here as a suggestion.

@jeremyzahner
Copy link
Contributor

@onnimonni I guess you could manage merging this yourself? =)

@onnimonni
Copy link
Contributor Author

I just didn't hear thoughts from anyone else. Does this look like something others would be interested as well?

@onnimonni
Copy link
Contributor Author

@jasonagnew I know you're busy, but do you have opinions 😃?

@jeremyzahner
Copy link
Contributor

@onnimonni I think it's great. What we (you) probably should do, is integrate such changes in a finished project done with Herbert to see if it is working as intended.

@onnimonni
Copy link
Contributor Author

That's harder for me to do because the project where I used these is closed source and owned by my client. I can hopefully do unit tests instead.

@jeremyzahner
Copy link
Contributor

@onnimonni Yeah, merging all kind of new functionality much quicker will become easier once we get proper unit tests for the framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants