In our application we went a step further and moved the whole caching 
definition to the configuration.

First we define cache adapters:

        <adapters>
            <adapter name="Memcache">
                <prefix>memcache100</prefix>
                <hosts>
                    <host name="memcache01" />
                    <host name="memcache02" />
                </hosts>
            </adapter>
            <adapter name="S3">
                <prefix>aws</prefix>
                <bucket-name>%aws.aws.s3.bucket.name%</bucket-name>
                <s3-service-id>s3.service</s3-service-id>
            </adapter>
            <adapter name="APC">
                <prefix>apc</prefix>
            </adapter>
        </adapters>

A cache adapter definition defines how to access the cache instance 
(hostnames, passwords, ...).

Now for each cache use case we define a "cache class":

        <classes>
            <class name="navigation">
                <adapter>Memcache</adapter>
                <prefix>navigation</prefix>
                <lifetime>60</lifetime>
            </class>
            <class name="profiler">
                <adapter>Memcache</adapter>
                <prefix>profiler</prefix>
                <lifetime>7200</lifetime>
            </class>
            <class name="metadata">
                <adapter>APC</adapter>
                <prefix>metadata</prefix>
                <lifetime>360</lifetime>
            </class>
        </classes>

A cache class defines what to cache ("navigation", "metadata", ...) and how 
to cache it (location, cache key prefixes, cache duration).

When using the cache in the code, the cache service has two simple methods:
    function get($className, $key);
    function set($className, $key, $value);

A real world usage looks like this:
    $this->objectCache->set('navigation', 'overviewStructure', 
$overviewStructure);
    $this->objectCache->set('navigation', 'detailTop', $detailTop);
    $this->objectCache->get('navigation', 'overviewStructure');

So the code itself knows nothing about where and how the objects are 
cached. Since everything is in the configuration we can move to different 
cache infrastructures or modify caching times without changing a singe line 
of code.
This is different from most cache solutions where you usually have to 
provide the cache duration in the code. I think this has many benefits if 
the code is not used in a single application but in a library or framework 
scenario.

If anyone is interested i can check if we can open source this component.

Regards,

Sven

-- 
-- 
If you want to report a vulnerability issue on Symfony, please read the 
procedure on http://symfony.com/security

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Symfony developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to