Skip to content
This repository

New Cache Package #1342

Closed
wants to merge 2 commits into from

11 participants

Louis Landry Piotr Gary A Mort Sam Moffatt Matias Griese Florian Voutzinos Andrew Eddie ianmacl Don Gilbert elinw javier gomez
Louis Landry

This is not ready to be merged, but I wanted to start the conversation about how we dramatically simplify the caching package for Joomla. The existing system is entirely too complex and doesn't honor the principle of separation of concerns. Hopefully this can serve as a starting point for us to figure out what caching looks like for Joomla in the longer term. As with everything these days I'm striving for simple, clear and concise.

Piotr

I'm quite happy with JCache shipped with 12.1.

But few things I've been missing:

  • not possible to overwrite some of the cache options (which are set based on CMS settings).
  • I'd like to save in image in cache before start to manipulate it using JImage. Manipulated image should be stored in cache as well until User decides to save it in image format and not JCache format. I ended up doing it without JCache.
Gary A Mort

Hm, I'd rather go in the opposite direction and allow for more complex settings such as Stash: https://github.com/tedivm/Stash

I'm also not thrilled with losing the group/pool/bin setting on the cache.... I realize that almost no one uses it though so that's likely just me.

With Stash, instead of having that special runtime property for caching in memory, it adds an "ephermeral" stash handler which keeps it treated by itself.

Moreover, their recent commits include a configurable Multihandler cache storage handler which can be configured to use multiple cache backends intelligently...ie for incredibly large objects[say the JDocument object] the cache can be to Ephemeral + File, really small objects could go to Ephemeral + APC[with it's shared memory model], and everything else can go to Ephemeral + Memcache

The cool factor is on lookups, it will check in all configured storage areas in an optimized order, ie check Ephemeral, then APC, then Memcache - so lookups take a small hit equal to all the failures[variables from Ephemeral.

Sam Moffatt

I'd suggest that for someone wanting a more complete cache library with more complicated caching strategies that they could then look into using Stash. Given you point out yourself that almost nobody uses it, it doesn't make sense to maintain a feature that is barely used and is better supported elsewhere in place of providing a simpler and more reliable caching mechanism to meet the majority of use cases.

Matias Griese

+1 for the simplification -- except that there's really a need to clean up the whole cache. For example in Joomla! 1.5 there was no way to clean up APC cache, which in many cases meant that you had to disable caching and put it back on after few hours to make changes visible. Or you needed to log in the server and do it from command line. Fortunately it's possible in Joomla! 2.5. :)

There's also a need to free up disk space when using file cache, otherwise unused cache entries will slowly fill up the disk.

Florian Voutzinos

+1 but I think it should be possible to inject a Memcached object in the constructor of JCacheMemcached, allowing a null value and calling _connect() as fallback.

Louis Landry

That's an interesting idea @florianv ... I honestly hadn't thought of that.

@mahagr I agree that in general that is a need. I'll take a look at it, but that wasn't really the exercise here. Mostly I am trying to get a feel for how people see the simplification and straightforward approach. I think we've always been too complex in how we deal with cache with all these controllers and handlers and such.

Thanks for the feedback guys!

Florian Voutzinos

@LouisLandry I think about that because in the future we will probably have a dependency injection container holding the JRegistry options and it's likely we will also get drivers from him. So I think there should be a way to inject them via constructor or setter.

Sam Moffatt pasamio closed this October 16, 2012
Louis Landry LouisLandry reopened this October 16, 2012
Louis Landry LouisLandry closed this October 16, 2012
Louis Landry LouisLandry reopened this October 16, 2012
Louis Landry LouisLandry closed this October 17, 2012
Louis Landry LouisLandry reopened this October 17, 2012
Louis Landry LouisLandry closed this October 17, 2012
Louis Landry LouisLandry reopened this October 17, 2012
Louis Landry LouisLandry closed this October 17, 2012
Louis Landry LouisLandry reopened this October 17, 2012
elinw elinw commented on the diff November 11, 2012
libraries/joomla/cache/cache.php
((32 lines not shown))
32 32
 
33 33
 	/**
34  
-	 * Constructor
  34
+	 * Constructor.
4
elinw
elinw added a note November 11, 2012

Why?

Why ask why?

elinw
elinw added a note November 28, 2012

Because I can.

That can be fixed. :wink:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
elinw elinw commented on the diff November 11, 2012
libraries/joomla/cache/memcached.php
((16 lines not shown))
  16
+ * @subpackage  Cache
  17
+ * @since       12.3
  18
+ */
  19
+class JCacheMemcached extends JCache
  20
+{
  21
+	/**
  22
+	 * @var    Memcached  The memcached driver.
  23
+	 * @since  12.3
  24
+	 */
  25
+	private $_driver;
  26
+
  27
+	/**
  28
+	 * Constructor.
  29
+	 *
  30
+	 * @param   JRegistry  $options  Caching options object.
  31
+	 *
3
elinw
elinw added a note November 11, 2012

Why? Why all these periods?

Because they are the Best. Descriptions. Ever.

javier gomez Owner

@elinw the period makes the code assistant of the IDE to stop showing more information. When you put a mouse over a function/method, the IDE usually shows the description of this method on a tooltip. If there is no dot/period, the code assistant continues reading showing something like: Constructor @param JRegsitry.... instead of only showing the description of the method: Constructor. I guess Louis did it for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Andrew Eddie
Owner

How are you thinking of instantiating the cache objects (or are we not there yet)?

Louis Landry

I was thinking something like $cache = new JCacheApc;. What do you think?

Andrew Eddie
Owner

I was just wondering if you wanted to include a getInstance($driver) convenience method. I'm just thinking of the case where the driver type is coming out of a configuration setting.

ianmacl
Owner

It would probably have to be getInstance($options) and $options would have to have a 'type' or 'driver' property. I would be okay with that so long as it doesn't try and cache cache objects. That isn't JCache's job.

Andrew Eddie
Owner

Or we add a factory class...

Don Gilbert
Owner

@ianmacl what other properties would be present in the $options array that would warrant such an implementation, rather than just passing the driver string?

ianmacl
Owner

Sorry Don, didn't see the question before. Different cache drivers would obviously have different options. If you were using memcached, for example, you might have the address or IP of the memcache server(s) or other connection info. For a file cache you might want to have a configuration option for the root path of the cache folder. For a database cache, you might want to be able to inject in a database driver object.

Don Gilbert
Owner
Florian Voutzinos

It's worth looking at https://github.com/fabpot/Pimple . It's a really simple dependency injection container that we could use to replace the factory.

If we want a configuration file to define the dependencies, it becomes suddently more complicated because we need to check for circular references : A needs B, B needs A. The dependencies must be seen as a graph, and each param/service is a node.

Andrew Eddie
Owner

Closing this PR as it is incorporated into the new Joomla Framework.

Andrew Eddie eddieajau closed this March 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.