• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Caching Functions

#11
[eluser]gRoberts[/eluser]
All you need to do is store the value in either a database or memcache. If the date since you last got the hostname is longer then say 5/10 minutes, get it again otherwise return back the value from the database/memcache.

I'm using memcache to serve 95% of my data. Basically I have functions that check to see whether there is data. If so, it gets it, otherwise it queries the database, caches the result and returns the results.

When ever anything is changed, the related cache is updated.

#12
[eluser]Mirage[/eluser]
Just a note that memcache, APC, XCache, etc are all possible candidates but have nothing to with CI and may not be available on the target server. Addressing them directly is thus really not recommended as your site may stop to function as you move between environments. It would be best to adopt a library which can abstract the various backend into a common interface. Zend_Cache provides this although it might seem a bit heavy for the novice. There are some solutions in Pear and also some libraries coded up by fellow Igniters. Search the Wiki for 'Cache'.

Cheers,
m

#13
[eluser]vlad_ci[/eluser]
@Flesha
It appears that you want to cache 'results of function calls',
not functions.

You then have to decide if your caching is for a specific user
or system wide.

Caching for specific user can be done using PHP native session support
or code igniter session library (but my understanding that code igniter
session library, since it is based on cookies can only store 4 bytes)




System wide caching should be done using one of the PHP caching mechanisms
There was a person here on the forums who created
khcache small library. Search for it, it should help to get things going.
It can use either APC (which is now a separate module but will be part of
PHP in 6.0) or memcache.


All the caching strategies in PHP use a basic mechanism of taking a result that you want to cache, making it
into a string, and then storing that string somewhere in a file or memory of
another process.

I am new to PHP but in my research,
there is no way to do what you would typically do in state-full systems
where you could instanciate class (functions and data) and keep it in
Process memory for as long as needed.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.