mouseywings Posted April 21, 2015 Share Posted April 21, 2015 Ok so this is how my collection looks when pulling from the database: http://pastebin.com/xrdGr4bU 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! Quote Link to comment https://forums.phpfreaks.com/topic/295734-need-more-insight-on-caching-when-pagination-is-involved/ Share on other sites More sharing options...
IThinkMyBrainHurts Posted April 21, 2015 Share Posted April 21, 2015 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...!? Quote Link to comment https://forums.phpfreaks.com/topic/295734-need-more-insight-on-caching-when-pagination-is-involved/#findComment-1509547 Share on other sites More sharing options...
mouseywings Posted April 21, 2015 Author Share Posted April 21, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/295734-need-more-insight-on-caching-when-pagination-is-involved/#findComment-1509551 Share on other sites More sharing options...
IThinkMyBrainHurts Posted April 21, 2015 Share Posted April 21, 2015 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??? Quote Link to comment https://forums.phpfreaks.com/topic/295734-need-more-insight-on-caching-when-pagination-is-involved/#findComment-1509555 Share on other sites More sharing options...
mouseywings Posted April 21, 2015 Author Share Posted April 21, 2015 (edited) 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 April 21, 2015 by mouseywings Quote Link to comment https://forums.phpfreaks.com/topic/295734-need-more-insight-on-caching-when-pagination-is-involved/#findComment-1509558 Share on other sites More sharing options...
IThinkMyBrainHurts Posted April 21, 2015 Share Posted April 21, 2015 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... Quote Link to comment https://forums.phpfreaks.com/topic/295734-need-more-insight-on-caching-when-pagination-is-involved/#findComment-1509561 Share on other sites More sharing options...
IThinkMyBrainHurts Posted April 21, 2015 Share Posted April 21, 2015 You are aware of the LIMIT keyword in databases? Quote Link to comment https://forums.phpfreaks.com/topic/295734-need-more-insight-on-caching-when-pagination-is-involved/#findComment-1509562 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.