Jump to content
mouseywings

Need more insight on caching when pagination is involved

Recommended Posts

Ok so this is how my collection looks when pulling from the database:

 


 



array (size=43)
0 =>
array (size=
'id' => int 1
'topic_id' => int 1
'user_id' => int 3
'body' => string '<p>Right after this I will change my permissions and see if I can only reply and not create!</p>' (length=96)
'hidden' => int 0
'likes' => int 1
'created_at' => string '2015-04-08 13:00:34' (length=19)
'updated_at' => string '2015-04-19 16:34:06' (length=19)
1 =>
array (size=
'id' => int 2
'topic_id' => int 1
'user_id' => int 3
'body' => string '<p>Seeing if I can reply!</p>' (length=29)
'hidden' => int 0
'likes' => int 0
'created_at' => string '2015-04-08 14:08:40' (length=19)
'updated_at' => string '2015-04-19 16:34:08' (length=19)
2 =>
array (size=
'id' => int 3
'topic_id' => int 1
'user_id' => int 3
'body' => string '<p></p>

<p>Testing reply as an artist! <br /></p>' (length=53)
'hidden' => int 0
'likes' => int 1
'created_at' => string '2015-04-09 14:06:46' (length=19)
'updated_at' => string '2015-04-19 16:34:13' (length=19)
3 =>
array (size=
'id' => int 4
'topic_id' => int 1
'user_id' => int 3
'body' => string '<p>Testing a new comment!</p>' (length=29)
'hidden' => int 0
'likes' => int 0
'created_at' => string '2015-04-15 14:53:05' (length=19)
'updated_at' => string '2015-04-15 14:53:05' (length=19)
.................


 

However when it gets to be over 100 items long.. I'm trying to make it so if I make an edit to ID 5, I can JUST make an edit to that one and re-cache it without having to flush all those items out of the cache and then regrab them.. because that will get pretty hectic I think especially if they are edited like every 2 minutes or whatever. Is there a way to make the array INDEX the value of the post ID? Or would I have to loop through them after grabbing them to do so? I just want to be able to make it like:

 



$data = $this->getPosts( $id ); // This will grab that array that you see above
$data[$id]->body = $newBody;

// And then code to recache the data (overwrite the cache key with the new data)


 

Thanks for any help!

Share this post


Link to post
Share on other sites

You could build a separate array of keys and use that for access. However you'd have to build it. Which leads to...

 

I may have another way but would be easier to see the get_posts() function!

 

 

However, when you say cache, are you storing all these in a session variable? Else, you're retrieving it all again anyway...!?

Share this post


Link to post
Share on other sites

You could build a separate array of keys and use that for access. However you'd have to build it. Which leads to... I may have another way but would be easier to see the get_posts() function! However, when you say cache, are you storing all these in a session variable? Else, you're retrieving it all again anyway...!?

 

I'm using Laravel for the get_posts() so I'm not sure if you could follow along. I'm storing all of these in a cache file (.txt), not a session.

Share this post


Link to post
Share on other sites

I'm using Laravel for the get_posts() so I'm not sure if you could follow along. I'm storing all of these in a cache file (.txt), not a session.

 

Well if you can't do it at that level then you'll have to either use the lookup method mentioned before or refactor it before storing in the txt file db thing you're using!

 

A txt file, how are you parsing that? Is that optimal???

Share this post


Link to post
Share on other sites

Well if you can't do it at that level then you'll have to either use the lookup method mentioned before or refactor it before storing in the txt file db thing you're using!

 

A txt file, how are you parsing that? Is that optimal???

 

Well right now in my method, I'm grabbing ALL results (from a cache) and then paginating those results. If I cache during the pull, wouldn't I have to do like Page 1 cache, Page 2 cache and end up storing like 50 cache results per topic if it were to hit 50 pages? That would be an insane amount of caches per topic when I could just do one. That's why I was trying to keep it that way.

 

I just dislike how I have to flush the entire cache and recache the entire topic posts if just one post was edited or liked.

Edited by mouseywings

Share this post


Link to post
Share on other sites

I don't get why you're caching them to file at all! Especially why get them all, store them again and then show some, why not just get some and dump 'em out to the client, much more efficient on the DB, file and PHP parser...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.