Home » Caching » Cache_Lite » Bug #5103
get should return references
Details
| Request #5103 | get should return references |
|---|---|
| Submitted | 2005-08-16 12:00 UTC |
| From | rumata at gmx dot co dot uk |
| Assigned | fab |
| Status | Wont fix |
| Package | Cache_Lite |
| PHP Version | Irrelevant |
| OS | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2005-08-16 12:00 UTC] rumata at gmx dot co dot uk
Description:
------------
In my application I use objects that should have only one instance. To achieve this (rather common, I believe) goal, I'm using references.
It seems to me very strange that Cache_Lite doesn't allow me to have my object persisted in memory "as is", so that it could return references to them
I'll rewrite some code to get this functionality, but hope this ability will be included in future releases
[2005-08-16 16:30 UTC] rumata at gmx dot co dot uk
Well. Small example. It's just an example. Don't take it too seriously.
Let's say I have a tree class named Node. And I have an instance method that retrieves (in some way) all children for current node.
Ex.
$tree =& getTreeRoot(); // it's a singleton of type Node
var_dump($tree->_children); // array()
$tree->populateChildren();
var_dump($tree->_children); // array(object, object, ..., object)
Now I'd like to have this nodes saved in cache. I don't even need in the moment to save them in persistant cache, just in memory.
1. I have $node (of type Node)
2. I call $cache->save($node->node_id, 'node');
3. Now I call $node->populateChildren();
4. Few lines of code later I call $node2 = $cache->get($node_id, 'node');
Now $node and $node2 are different objects. $node has it's children already populated and $node2 doesn't have any children. It will have to populate them again.
I'd like to use cache in this way:
1. I have $node (of type Node)
2. I call $cache->save($node, $node->node_id, 'node');//here $node is passed by reference
3. Now I call $node->populateChildren();
4. Few lines of code later I call $node2 =& $cache->get($node_id, 'node');//mention & !!!
Now $node and $node2 point to one object. Both of them have their children populated. If I'm using $node2 I don't need to repopulate them again.
Please feel free to ask if something seems unclear.
[2005-08-17 18:01 UTC] rumata at gmx dot co dot uk
sure I do!
I need it, when saving data into file
[2005-08-18 16:37 UTC] rumata at gmx dot co dot uk
Well, I'm not talking about possibilities, because I've already implemented this feature (as well, as nested calls) =)
I'm talking about implementing it in original version, in case someone other than me runs into same problem.
Let me try to explain:
I'm talking about in memory caching only! It would be great to change in memory cache implementation slightly to make it possible using references.
May be I could mail you my version of Lite.php?
[2005-09-19 21:39 UTC] fab at php dot net
Thanks for the patch. I review it for the next version
[2005-11-17 09:33 UTC] fab at php dot net
The patch is ok but competly specific to memoryCaching. I don't want to introduce a such specific thing.
In a next major version, I will split memory caching out of the Cache_Lite kernel and then I will reconsider it.
Thanks anyway.