Skip to content

Conversation

@wshafer
Copy link
Contributor

@wshafer wshafer commented Apr 14, 2014

Based on Ocramius review of PR #127, I have taken a stab at refactoring the Asset Cache Manger to pull services from the SM where possible.

The provider factory now accepts 4 ways to configure the cache. Callback, A Zend Service, Class name, and a BC mapper for things like "APC"

Possible way's to configure the caches are as follows:

return array(
    'asset_manager' => array(
        'caching' => array(
            //Callback method for BC
            'callback_example.tmp' => array(
                'cache'     => function() {
                    return new myCache();
                },
            ),
            // Zend Service Key
            'zend_service_example.tmp' => array(
                'cache'     => 'myZf2ServiceManagerService',
            ),

            // Classname
            'class_name_example.tmp' => array(
                'cache'     => 'AssetManager\\Cache\\FileManager',
                'options'   => array(
                    'dir' => 'someDir',
                ),
            ),

            // BC Definitions
            'bc_example.tmp' => array(
                'cache'     => 'Apc',
            ),
        ),
    ),
);

Also attached is a Zend Cache Adaptor for Assetic. In order for this to work the adapter needs the cache injected. As such I have only set this up to be used via the service manager.

To configure this adapter here is one possible solution:

File: MyApplication/Module.php

<?php

namespace Application;

use AssetManager\Cache\ZendCacheAdaptor;
use Zend\Cache\StorageFactory;

class Module
{
    public function getServiceConfig()
    {
        return array(
            'factories' => array(
                'AssetManagerCache' => function ($serviceLocator) {
                    $zfCacheConfig = array(
                        'adapter' => array(
                            'name' => 'Memcached',
                            'options' => array(
                                'servers' => array(
                                    array('localhost','11211'),
                                ),
                                'namespace' => 'zfcache',
                            ),
                        ),
                        'plugins' => array(),
                    );

                    $zendCacheStorage = StorageFactory::factory($zfCacheConfig);

                    return new ZendCacheAdaptor($zendCacheStorage);
                },
            ),
        );
    }
}

And my config/autoload/local.php config would look like:

<?php

return array(
    'asset_manager' => array(
        'caching' => array(
            'default' => array(
                'cache'     => 'AssetManagerCache'
            ),
        ),
    ),
);

@wshafer
Copy link
Contributor Author

wshafer commented Apr 21, 2014

@Ocramius - Have you had time to look this one over? Just wondering if I need to make any modifications while it's on my radar. Thanks

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backwards compatibility compatibility? :p

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't have to be. That was based on the conversation in the last PR, which sent me down this road. ;)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I mean, you wrote "BC compatibility" but the "C" in "BC" stands for compatibility. So you wrote Backwards compatibility compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. I just added it for comical relief. Pretty funny isn't it? :p I'll fix.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:p

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment on why this is still here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "I'm too lazy to find all the references to this" work? :p

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope :P

Westin Shafer added 4 commits May 2, 2014 11:05
…ssetManager test to use a mock cache manager instead of the actual class, tests for the Cache Manager now have their own test file.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, what about BC? If anyone uses this they're boned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think they'll use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the alias back for that. Just in case. Also made a comment for @Ocramius. 👍

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesomesauce. I just really like BC. It's my favorite. Next to peanut butter jelly sandwiches, but that's logic.

@wshafer
Copy link
Contributor Author

wshafer commented May 2, 2014

@Ocramius - Okay, refactored so only the needed caches are being instantiated. See if this is more to your liking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, These were removed because they test the Asset Manager Cache and not the Asset Manager itself. The Asset Manager Cache is now being tested on it's own.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docblock

@Ocramius
Copy link
Contributor

Ocramius commented May 4, 2014

@wshafer looks much better to me!

Westin Shafer added 3 commits May 5, 2014 09:58
Removed unneeded doc blocks
Moved config to constructor + factory and updated unit tests for the asset cache manager.
Changed order for asset cache provider discovery and return from method as soon as resource is found.
@wshafer
Copy link
Contributor Author

wshafer commented May 5, 2014

There ya go @Ocramius and @RWOverdijk . Refactored based on our previous conversations.

@Ocramius
Copy link
Contributor

Ocramius commented May 5, 2014

Looking good to me.

@RWOverdijk
Copy link
Owner

Mhm, agreed. You did one hell of a job. I think, to be on the safe side, I'm tagging this 1.4.0. Well done :)

@Ocramius
Copy link
Contributor

Ocramius commented May 6, 2014

@wshafer could you add wiki entries for the new zend cache provider?

@wshafer
Copy link
Contributor Author

wshafer commented May 6, 2014

@Ocramius - Of course. As long as someone proofs it. English writing is not one of my strengths (as you've probably already guessed). ;)

@Ocramius
Copy link
Contributor

Ocramius commented May 6, 2014

@wshafer don't worry that much about it as long as there is understandable documentation.

@RWOverdijk
Copy link
Owner

And I'll go through it. :)

@wshafer
Copy link
Contributor Author

wshafer commented May 6, 2014

@RWOverdijk - Ok see if the new edits make sense. Thanks.

@wshafer
Copy link
Contributor Author

wshafer commented May 10, 2014

@RWOverdijk & @Ocramius - I was just re-reading my wiki edits and one thing hit me. It is really complicated to configure the ZendCacheAdaptor. Would it make more sense for it to follow the current caches and add it to the class mapper? This would make it simple to use with config just like the others. Here's what I'm thinking.

file: module.config.php

return array(
    'asset_manager' => array(
        'caching' => array(
            'default' => array(
                'cache'     => 'AssetManager\\Cache\\ZendCacheAdapter'
                'options' => array(
                    'service' => 'myZendService'
                ),
            ),
        ),
    ),
);

Thoughts?

@Ocramius
Copy link
Contributor

@wshafer well, that is pretty much the orientation that I took with anything related to including third-party services.

@RWOverdijk
Copy link
Owner

I think that's @Ocramius his way of saying "good idea". Not sure. :p

@RWOverdijk
Copy link
Owner

@Ocramius Do you want it added to the class mapper or can I merge?

@Ocramius
Copy link
Contributor

It can be done as a cleanup afterwards.

RWOverdijk added a commit that referenced this pull request May 22, 2014
Refactor asset cache Manager + Zend Cache Adaptor
@RWOverdijk RWOverdijk merged commit 7f1c4f3 into RWOverdijk:master May 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants