Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4255
Latest: andreios
New This Month: 3
New This Week: 1
New Today: 0
Stats
Total Posts: 43259
Total Topics: 7518
Most Online Today: 282
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 288
Total: 288

Author Topic: Caching query problem  (Read 3091 times)

0 Members and 1 Guest are viewing this topic.

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Caching query problem
« on: September 28, 2015, 10:34:26 pm »
Hello,

I'm trying to cache this database query, but I'm not doing it right according to the APC logs:

Code: [Select]
$cachename = 'latest_blog_news';
if (($latest_blog_news = cache_get_data($cachename, 90)) == null)
{
$dbresult = db_query("
SELECT subject, posted_time
FROM {$db_prefix}blog_articles
        ORDER BY posted_time DESC
LIMIT 1", __FILE__, __LINE__);

list ($subject) = mysql_fetch_row($dbresult);
mysql_free_result($dbresult);

$latest_blog_news = "<span style=\"color: #33587a;font-weight:bold;\">Read:</span> <a href=\"http://biology-forums.com/index.php?blog=1.0#new\" style=\"font-weight: bold;\">".$subject." <i style=\"font-size: 90%;\" class=\"fa fa-rss-square\"></i></a>\n";

// Check if cache is enabled
global $modSettings;
if (!empty($modSettings['cache_enable']))
cache_put_data($cachename, $latest_blog_news, 90);
}

Here's what is being stored:

Code: [Select]
's:249:"<span style="color: #33587a;font-weight:bold;">Read:</span> <a href="http://biology-forums.com/index.php?blog=1.0#new" style="font-weight: bold;">Craving a Big Mac? I don&#039;t blame you <i style="font-size: 90%;" class="fa fa-rss-square"></i></a>
";'

Of course, I would like the database query stored as well. I know it's a tiny query, but it's still better to cache it. Any thoughts?

Offline nend

  • Member
  • *
  • Posts: 14
    • View Profile
    • SIComm.us
Re: Caching query problem
« Reply #1 on: October 30, 2015, 11:13:23 pm »
Looks OK to me,

First problem, your only caching for 90 seconds, which is useless IMHO if your going to be caching that data.

Second you don't have to check if the cache is enabled, SMF handles that in the cache function.

Third, not everything needs to be cached, simple queries that don't strain your database server should not be cached. Think about it this way, anything that is cached resides in the systems memory. While memory is faster than physical storage, you still have less of it, so pick wisely on what you want to keep in there. If it is easy for the DB server to handle then let it handle it, if not then load it into memory, it is a balancing act. ;)

 

Related Topics

  Subject / Started by Replies Last post
3 Replies
7207 Views
Last post August 19, 2008, 09:14:06 am
by gibbs
6 Replies
7193 Views
Last post February 09, 2009, 07:13:38 pm
by SMFHacks
6 Replies
8219 Views
Last post April 12, 2011, 03:31:19 pm
by bruno
3 Replies
3592 Views
Last post December 09, 2014, 12:35:39 pm
by shuban
6 Replies
4286 Views
Last post December 20, 2016, 05:34:39 pm
by shuban

+- Recent Topics

No thumbnails on new uploads by SMFHacks
March 27, 2024, 02:10:41 pm

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

an idea for new mod (( content type with different display )) by SMFHacks
February 27, 2024, 01:36:27 pm

[Mod] RSS Feed Poster by SMFHacks
February 27, 2024, 11:57:18 am

find duplicate pictures by fvlog19
February 14, 2024, 02:22:40 pm

Error uploading video. by SMFHacks
February 08, 2024, 02:04:16 pm

Gallery icon as last added image by fvlog19
February 01, 2024, 01:04:56 pm

Powered by EzPortal