Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Caching problem?

by viffer (Beadle)
on Mar 16, 2010 at 09:18 UTC ( #828857=perlquestion: print w/replies, xml ) Need Help??

viffer has asked for the wisdom of the Perl Monks concerning the following question:

First post - please don't bite too hard.

I've read what I can and googled till I'm blue in the face but can't find what I'm looking for. I'm relatively new to Perl so please bear with me.

I've written a script which enables people to change dates on line.

I take the data they've entered, compare it to the existing file, then either write the existing record or the amendments to a new file.

Having done then I delete the original file, rename the new file to that of the original and display the data on the screen.

When I look in the file it has the data written correctly, but what displays is the data in the original file - as though it's displaying what's in the cache.

So my question (rather long windedly is) is there an EASY method of clearing the cache or might it be something else?

I'm happy to post the code (and give you all a laugh at my expense) but it's rather large. I do uses system rm commands rather than perl MOVE commands but I can't see that would make much difference given that the contents of the file I'm reading from are correct.

Appreciate any time any of you spend helping me.

Kev

Replies are listed 'Best First'.
Re: Caching problem?
by Corion (Patriarch) on Mar 16, 2010 at 09:29 UTC

    Without seeing the program, I can see two possible causes:

    1. Your program is reading (what it thinks is) the new data from the old file through an open file handle to the old file. If you keep a file handle open to a file, some operating systems allow you to unlink or rename the file to a new name and still read the data from it through the filehandle. This is only testable by inspecting your program and looking at the control flow. I recommend ripping out all CGI-related functionality and first making sure that the program works correctly from the command line, updating the file and displaying the correct data set.
    2. Your browser caches the data and displays the old data. This should be easily verified by reloading the page from the browser.
    3. You're using some data caching and a persistent environment like mod_perl. Then you have to update or invalidate your cache as well as updating the file on disk.

    A technique which I use fairly often to separate changing the data from displaying the data is to modify the data in one request and then send a Location: http://... redirect header to the page that then displays the (now changed) data. This allows me to nicely separate the two operations, at the cost of an additional HTTP request for every modification.

Re: Caching problem?
by jethro (Monsignor) on Mar 16, 2010 at 09:31 UTC
    Addendum to Corions answer: To invalidate your browser cache, just hit reload with the shift key pressed (works with firefox, might be a standard, if not try ctrl or alt key)
      Thanks for your help guys

      Changing the file handles has done the job.
      Refreshing the screen to check the cache wouldn't work as I was using ajax to put the response back onto the same page,
      so refreshing would take me back to the initial entry screen

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://828857]
Approved by Ratazong
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2022-05-25 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (90 votes). Check out past polls.

    Notices?