Friday, 15 July 2011

php memcache orm caching and purging -


Suppose I want to implement a memcache based caching for my ORM, similar to the data set on my user-model I have 2 ways to get:

  + findById (1234); + FindByU name ('Roman');  

Different questions, same results. Now both the resultsets are cached by memcache under different keys (containing mysql) after editing the user model is very bad when I clean it, I have to clean 2 keys which I do not know, because the keys Looking like this:

  + findById -> User_id_1234_visible_true_enabled_true (and so on) + findByU name - & gt; User_username_roman_visible_true_enabled_true (and so on)  

Now the question is, how can I clean both keys.

The only solution I found so far is to split the FindByU name into 2 mysql calls:

  1 FindIdByUsername () 2. Find the ID from Findet 3. FindById ( WithFetchedId) 4. Cash Search FindIm Resultset  

I hope there is a hint with another solution that I can come up with. Thx a lot!

One way to override is model :: find () and < Code> Model :: findFirst () The way described on that particular model. But I think this 100% does not solve your problem until that:

a) Depending on how many users you have in DB, > {Login: ID} - small / medium CRM case

b) or cache them for some time after they need to:

  1. If the user is not in the cache, get it from FindIdByUsername () and cache it under UserName 2. Find userID from cache based on username 3. FindById ()  

Therefore, in a real time, you will be asked from time to time, a question for a user ID based on main code based on GetUserById () , which is quite a fair approach.


No comments:

Post a Comment