Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6670607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:17:19+00:00 2026-05-26T03:17:19+00:00

Consider the following AJAX call to load RSS news data on click event: $(function()

  • 0

Consider the following AJAX call to load RSS news data on click event:

 $(function() {
            $(document).ready(function() {
                $('.msg_head').eq(0).click(function(){
                    $('.msg_body').eq(0).load('printSideNews.php');
                    $('.loadMessage').eq(2).hide();
                });
    });
});

printSideNews.php looks like this:

include ('newsFeed.php');
  function printNewsMenu($itemD){
    for ($i = 0; $i < 4; $i++) {
            if($itemD==null)
            echo "An error has occured, please try again later";
            $article_title = $itemD[$i]->title;
            $article_link = $itemD[$i]->link;
            echo "<a href='".$article_link."' title='".$article_title."' target='_blank'>". $article_title. " </a></br>". PHP_EOL;
}
printNewsMenu($itemD);

The included newsFeed.php file lloks like:

$urlD = "someurl";
    $xmlD = simplexml_load_file($urlD);
    $itemD = $xmlD->channel->item;

I need to cache the $itemD or the $xmlD object – not sure which one. This should be cached for 1 hour then taken again from the url. Any help with code caching this mess will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:17:20+00:00Added an answer on May 26, 2026 at 3:17 am

    take a look at this function:

        <?php      
        function cacheObject($url,$name,$age = 86400)
          { 
            // directory in which to store cached files
            $cacheDir = "cache/";
            // cache filename constructed from MD5 hash of URL
            $filename = $cacheDir.$name;
            // default to fetch the file
            $cache = true;
            // but if the file exists, don't fetch if it is recent enough
            if (file_exists($filename))
            {
              $cache = (filemtime($filename) < (time()-$age));
            }
            // fetch the file if required
            if ($cache)
            {
              $xmlD = simplexml_load_file($url);
              $itemD = $xmlD->channel->item;
              file_put_contents($filename,serialize($itemD));
              // update timestamp to now
              touch($filename);
            }
            // return the cache filename
            return unserialize(file_get_contents($filename));
          }     
    
    
    $urlD = "someurl";
    
    $itemD = cacheObject($urlD,'cacheobject',3600);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: MyClass.prototype.my_func = function () { this.x = 10; $.ajax({ //
I don't understand how to use the XUI xhr (ajax) call. Consider the following
Let's consider following, simplified example: We have 2 tabs withing <rich:tabPanel switchType=ajax> , each
Consider the following snippet of code: function parseXml(xml) { xmlObject= xml; alert(xmlObject.xml); } function
Please consider the following code, <form action=index.php method=post name=adminForm enctype=multipart/form-data> <input type=hidden name=showtime[] id=showtime_1
Please consider the following view: <p>Count <span data-bind=text: unreadCount()>&nbsp;</span></p> <div data-bind='template: { name: conversationTemplate,
I think this should be simple. Say I've got the following jQuery: $someForm.live('submit', function(event)
Consider following JavaScript code (tested in Firefox): function f(a) { if (a == undefined)
Consider the following code: (live example here ) $(function() { var wrapper = $(<div
Consider the following partial, it gets inserted into a page if someone clicks AJAX

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.