Welcome Guest, Not a member yet? Register   Sign In
Problems with output cache
#11

[eluser]n0xie[/eluser]
Well one doesn't exclude the other. We use Phil's caching library as well as the native caching library, since they both cache different types of data. It seems to me you weight your options and chose what works for you,. I was just interested in what led your team to this decision.
#12

[eluser]Twisted1919[/eluser]
The "useless" from my point of view :
I have a database driven website , which always shows in the header the image of the user profile and some additional info about him . Doesn't matter the uri segment , the info is always there if the user is authed.
Now , guess what's happening if i login to the system , then the cache is created , if i logout from the system , what do you think i will see in the header ?
Even more , my users profiles are like www.domain.com/username.html , if the cache file is created while an authed user is previewing his www.domain.com/his-name.html where he can see additional controls , what do you think will see a guest by visiting the same url ?

I don't know about the way you use it , but for me is still useless .
#13

[eluser]n0xie[/eluser]
Quote:I have a database driven website , which always shows in the header the image of the user profile and some additional info about him . Doesn’t matter the uri segment , the info is always there if the user is authed.
Now , guess what’s happening if i login to the system , then the cache is created , if i logout from the system , what do you think i will see in the header ?
This is widget like behaviour and as I explained above, you can use ajax calls to solve this: make the default not to show the profile name/picture. Make an ajax call to verify identity. Return profile name/pic. Update DOM to show it. There you just saved yourself from having to rebuild your entire page every request with an ajax call which will probably use about 40 bytes. You can even use some shiny javascript effect making it look all cool and stuff. (fade in photo anyone?)

Let me put it this way: do you really hit the database each time someone loads a page just to show his profile name?

Quote:Even more , my users profiles are like www.domain.com/username.html , if the cache file is created while an authed user is previewing his www.domain.com/his-name.html where he can see additional controls , what do you think will see a guest by visiting the same url ?
Cache the public profile page. Make the edit profile page a different url. Don't cache the edit page. Problem solved. Caching strategy is not to cache everything, it's caching frequently visited pages.

How many people might view the profile? Might be your whole userbase. How many people might edit the profile? Most likely just 1. Which of the 2 do you think is worth caching?

tldr: CI's caching is not the best implementation possible. Issues with logged in/state could be a problem. Even so, it still has it's uses and is hardly useless.
#14

[eluser]Twisted1919[/eluser]
Yes , i see your point , but, as it's known the database is the bottleneck most of the time , so i prefer doing something like :
Code:
if( i-have-a-cached-array-of-objects )
   {
   ---get-the-cached-array-of-objects(for looping etc)
   }
else
   {
   ---make-a-database-call
   ---store-the-retrieved-array-of-objects-into-cache
   ---get-the-cached-array-of-objects
   }
---finally return the array of objects .

Seems easier to work that way .
Processing an object from cache will not require much memory/time even if is something big .
And if i want to save that processing time/memory i can just cache the result so i will not be needed to loop between my array of objects each time, just get the result from cache and display it directly .

So i would say, that your method is pretty good , but not so flexible as mine(not mine actually, but you got the pointTongue )
#15

[eluser]n0xie[/eluser]
Like I mentioned before, we do both. If you cache objects, you still have to rebuild the page on every request, which is still way more overhead then serving a static page from cache.
#16

[eluser]BigChase[/eluser]
Does the $this->output->cache(n) method only cache the content generated by the controller (or model) from which it is called or does it always cache the entire page?

Would be great to have the ability to cache only parts of the page (certain views, not all views). CakePHP's "elements" views have this ability. Does Codeigniter?
#17

[eluser]WanWizard[/eluser]
No, but there's an excellent alternative from Phil Sturgeon.
#18

[eluser]BigChase[/eluser]
Thanks Wan, looked at Phils cache. Should be very useful. Do you know what he means by caching "library calls" [as in the example he provides: $this->cache->library('some_library', 'calcualte_something', array($foo, $bar, $bla)) ] I understand caching a model call, but does caching a library call mean?

Thanks again.
#19

[eluser]cahva[/eluser]
From object point of view models and libraries are the same. So cache->library caches the method's output from the library class and cache->model caches the method's output from the model class. Simple as that.




Theme © iAndrew 2016 - Forum software by © MyBB