Skip to content

Instantly share code, notes, and snippets.

@aranw
Created November 24, 2012 12:24
Show Gist options
  • Save aranw/4139459 to your computer and use it in GitHub Desktop.
Save aranw/4139459 to your computer and use it in GitHub Desktop.
Caching issue
@extends('partials.template')
@section('content')
<div class="g two-thirds">
<h2>About Me</h2>
<p>
Back-end PHP Developer from Huddersfield, UK
</p>
<p>
More info coming when I know what to put here.
</p>
<p class=proceed><a href="{{ URL::to('about') }}" class="go">Read more...</a></p>
</div>
<div class="g one-third">
</div>
<div class="g one-whole">
<p>There will be other stuff here shortly</p>
</div>
@stop
@extends('partials.template')
@section('content')
<div class="g two-thirds">
<h2>Contact Me</h2>
<div id="wufoo-z7x3p9">
Fill out my <a href="http://aranw.wufoo.com/forms/z7x3p9">contact form</a>.
</div>
<script type="text/javascript">
var z7x3p9;(function(d, t) {
var s = d.createElement(t), options = {
'userName':'aranw',
'formHash':'z7x3p9',
'autoResize':true,
'height':'517',
'async':true,
'header':'show'
};
s.src = ('https:' == d.location.protocol ? 'https://' : 'http://') + 'wufoo.com/scripts/embed/form.js';
s.onload = s.onreadystatechange = function() {
var rs = this.readyState;
if (rs)
if (rs != 'complete')
if (rs != 'loaded') return;
try {
z7x3p9 = new WufooForm();
z7x3p9.initialize(options);
z7x3p9.display();
} catch (e) {}};
var scr = d.getElementsByTagName(t)[0],
par = scr.parentNode;
par.insertBefore(s, scr);
})(document, 'script');
</script>
</div>
<div class="g one-third social">
<h2>Social Links</h2>
</div>
@stop
<?php
class PageController extends Controller {
/**
* Blog Posts
*
* @var array
**/
protected $posts;
/**
* undocumented function
*
* @return void
* @author
**/
public function __construct(PostRepository $posts)
{
$this->posts = $posts;
}
public function showIndex()
{
$view = View::make('pages.index');
$view->with('title', "Aran Wilkinson - Web Developer");
// Get the 5 latest blog posts titles
$posts = $this->posts->getLatestPosts(5, array('id', 'title', 'slug'));
$view->with('posts', $posts);
return $view;
}
public function showAbout()
{
$view = View::make('pages.about');
$view->with('title', "About");
if (Cache::has('page.about'))
{
return Cache::get('page.about');
}
else
{
Cache::put('pages.about', $view, '2880');
return $view;
}
}
public function showContact()
{
$view = View::make('pages.contact');
$view->with('title', "Contact");
if (Cache::has('page.contact'))
{
return Cache::get('page.contact');
}
else
{
Cache::put('pages.contact', $view, '2880');
return $view;
}
}
}
<?php
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class NoPostsException extends Exception {}
class PostController extends Controller
{
/**
* Blog Posts
*
* @var array
**/
protected $posts;
/**
* undocumented function
*
* @return void
* @author
**/
public function __construct(PostRepository $posts)
{
$this->posts = $posts;
}
public function showIndex()
{
return Cache::remember('blog.index', '720', function()
{
$posts = $this->posts->getLatestPosts();
$posts = ($posts->isEmpty()) ? null : $posts;
return View::make('blog.index')->with('title','Aran Wilkinson - Blog')->with('posts', $posts);
});
// $view = View::make('blog.index');
// $view->with('title', "");
// //
// // Also pagination needs to be taken care of?
// //
// $view = $view->render();
// if (Cache::has('blog.index'))
// {
// return Cache::get('blog.index');
// }
// else
// {
// Cache::put('blog.index', $view, '2880');
// return $view;
// }
// return $view;
}
public function showPost($post_slug = null)
{
// We need our blog post before we get to our view
$post = $this->posts->getPostBySlug($post_slug);
// Might as well throw a error here if we have no post before we render anything!
$view = View::make('blog.post');
$view->with('title', "Aran Wilkinson - "); // We need to get the post title
$view->with('post', $post);
//
// Get the requested blog post
// If it doesn't exist give 404 error
//
return $view;
}
public function resolvePost($post_id)
{
$post = $this->posts->getPostById($post_id);
if ( $post )
{
return Redirect::to('blog/'.$post->slug);
}
else
{
// Trigger 404
throw new NotFoundHttpException('Unable to find that blog post');
}
}
}
Exception: Serialization of 'Closure' is not allowed
in /Users/aran/Sites/blog/vendor/illuminate/cache/src/Illuminate/Cache/FileStore.php line 75
at serialize() in /Users/aran/Sites/blog/vendor/illuminate/cache/src/Illuminate/Cache/FileStore.php line 0
at FileStore->storeItem('blog.index', object(View), '720') in /Users/aran/Sites/blog/vendor/illuminate/cache/src/Illuminate/Cache/Store.php line 114
at Store->put('blog.index', object(View), '720') in /Users/aran/Sites/blog/vendor/illuminate/cache/src/Illuminate/Cache/Store.php line 149
at Store->remember('blog.index', '720', object(Closure))
at call_user_func_array(array(object(FileStore), 'remember'), array('blog.index', '720', object(Closure))) in /Users/aran/Sites/blog/vendor/illuminate/support/src/Illuminate/Support/Manager.php line 127
at Manager->__call('remember', array('blog.index', '720', object(Closure)))
at CacheManager->remember('blog.index', '720', object(Closure))
at call_user_func_array(array(object(CacheManager), 'remember'), array('blog.index', '720', object(Closure))) in /Users/aran/Sites/blog/vendor/illuminate/support/src/Illuminate/Support/Facade.php line 56
at Facade::__callStatic('remember', array('blog.index', '720', object(Closure))) in /Users/aran/Sites/blog/app/controllers/PostController.php line 38
at Cache::remember('blog.index', '720', object(Closure)) in /Users/aran/Sites/blog/app/controllers/PostController.php line 38
at PostController->showIndex()
at call_user_func_array(array(object(PostController), 'showIndex'), array()) in /Users/aran/Sites/blog/vendor/illuminate/routing/src/Illuminate/Routing/Controllers/Controller.php line 131
at Controller->directCallAction('showIndex', array()) in /Users/aran/Sites/blog/vendor/illuminate/routing/src/Illuminate/Routing/Controllers/Controller.php line 116
at Controller->callAction(object(Application), object(Router), 'showIndex', array()) in /Users/aran/Sites/blog/vendor/illuminate/routing/src/Illuminate/Routing/Router.php line 509
at Router->Illuminate\Routing\{closure}()
at call_user_func_array(object(Closure), array()) in /Users/aran/Sites/blog/vendor/illuminate/routing/src/Illuminate/Routing/Route.php line 64
at Route->callCallable() in /Users/aran/Sites/blog/vendor/illuminate/routing/src/Illuminate/Routing/Route.php line 39
at Route->run(object(Request)) in /Users/aran/Sites/blog/vendor/illuminate/routing/src/Illuminate/Routing/Router.php line 538
at Router->dispatch(object(Request)) in /Users/aran/Sites/blog/vendor/illuminate/foundation/src/Illuminate/Foundation/Application.php line 243
at Application->dispatch(object(Request)) in /Users/aran/Sites/blog/vendor/illuminate/foundation/src/Illuminate/Foundation/Application.php line 223
at Application->run() in /Users/aran/Sites/blog/public/index.php line 51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment